我常要执行这样一类sql语句
select * from tableA where date='20003-6-30'
union all
select * from tableB where date='20003-6-30'
union all
select * from tableC where date='20003-6-30'
union all
select * from tableD where date='20003-6-30'可不可以将其中的'2003-6-30'设成一个变量代替,这样在执行sql语名前我只需更改变量的值即可
谢谢
select * from tableA where date='20003-6-30'
union all
select * from tableB where date='20003-6-30'
union all
select * from tableC where date='20003-6-30'
union all
select * from tableD where date='20003-6-30'可不可以将其中的'2003-6-30'设成一个变量代替,这样在执行sql语名前我只需更改变量的值即可
谢谢
在嵌入式sql中应该也是可以的
找找date的格式
首先说明你给的那几条语句应该说不完全正确。在SQL查询语句中使用变量有些不同!
如果是数值开变量!那么直接使用!字符型就是就得加单引号,那么日期型变量就得
加#,你给的那几条语句如果可以正常查询到你想得到的内容,那么只能说你的那个
字段是字符型的!而不是真正的日期型!因为日期型查询时必须加#!select * from tableD where date=#20003-6-30#
例:
dim SearchDate as date
SearchDate= '自己写
select * from tableD where date=#" & SearchDate & "#"
ss=data()
sqlcmd="select * from table where data=' + ss + '"
SELECT @theDate = '20003-6-30'select * from tableA where date = @theDate
union all
select * from tableB where date = @theDate
union all
select * from tableC where date = @theDate
union all
select * from tableD where date = @theDate
SELECT @theDate = '20003-6-30'select * from orderin where 入库日期 = @theDate执行后提示:
服务器: 消息 241,级别 16,状态 1,行 2
从字符串转换为 datetime 时发生语法错误。所以不得不再发贴请教了
SELECT @e1 = '上海av'
select * from korder where 办事处 = @e1执行后返回空集(无数据)
SELECT @e1 = '上海av'select * from korder where 办事处 = @e1