Using SQL with VBA in Excel

在利用ADO+SQL查询ACCESS数据库

VB中是这样的
?:任意单个字符 如LIKE ‘?南’ ,LIKE ‘?南?’
*:零个或多个字符 如:LIKE ‘*南’ , LIKE ‘*南*’

而在VBA中则不能这样用,它的用法竟然和SQL查询SQL Server数据库的语法一致:
_ :任意单个字符 如LIKE ‘_南’ ,LIKE ‘_南_’
%:零个或多个字符 如:LIKE ‘%南’ , LIKE ‘%南%’

Read the rest of this entry »

Some useful SQL for OLEDB

Get snapshot for all tags

SELECT tag, time, value, DIGSTRING(status) AS status FROM piarchive..pisnapshot

Get data for a digital tag

SELECT tag, time, DIGSTRING(CAST(value AS Int32)) AS value, DIGSTRING(status) AS status
FROM piarchive..picomp2
WHERE tag = 'cdm158' AND time >= 't'

Read the rest of this entry »