请各位帮忙看看这个存储过程哪有问题?谢谢

snowouldance 2009-11-20 10:08:04
这个存储过程(名称 test)输入的两个参数是
@dt1 datetime,
@dt2 datetime

set @sqlstr ='select sn, convert(char(10),Test_Datetime,120) as test_datetime,result into trxtemp0 from [' + @tablename1 + '] where test_datetime between ' + convert(varchar(30),@dt1,120) + ' and ' + convert(varchar(30),@dt2,120)
exec(@sqlstr)


在查询分析器执行这个存储过程
test '2009-11-12' , '2009-11-16'

报了错,不知道这个错误如何解决,求帮助,谢谢大家
服务器: 消息 170,级别 15,状态 1,行 1
第 1 行: '00' 附近有语法错误。
...全文
104 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
jimwoo 2009-11-20
  • 打赏
  • 举报
回复
set @sqlstr ='select sn, convert(char(10),Test_Datetime,120) as test_datetime,result  into trxtemp0 from [' + @tablename1 + '] where convert(varchar(30), test_datetime, 120) between ''' + convert(varchar(30),@dt1,120) + ''' and ''' + convert(varchar(30),@dt2,120)+'''' 
exec(@sqlstr)
laker_914 2009-11-20
  • 打赏
  • 举报
回复

@tablename1

这个从哪来啊?

忆轩辕 2009-11-20
  • 打赏
  • 举报
回复


set @sqlstr ='select sn, convert(char(10),Test_Datetime,120) as test_datetime,result into trxtemp0 from [' + @tablename1 + '] where test_datetime between ' + @dt1+ ' and ' + @dt2

exec(@sqlstr)

--这样?

snowouldance 2009-11-20
  • 打赏
  • 举报
回复
谢谢大家 问题解决 结贴 这个'号 害了我很多次了呵呵
--小F-- 2009-11-20
  • 打赏
  • 举报
回复
set @sqlstr ='select sn, convert(char(10),Test_Datetime,120) as test_datetime,result into trxtemp0
from [' + @tablename1 + '] where test_datetime between ''' + convert(varchar(30),@dt1,120) + ''' and ''' + convert(varchar(30),@dt2,120)+''''
jiangshun 2009-11-20
  • 打赏
  • 举报
回复
set @sqlstr ='select sn, convert(char(10),Test_Datetime,120) as test_datetime,result  into trxtemp0 
from [' + @tablename1 + '] where test_datetime between ''' + convert(varchar(30),@dt1,120) + ''' and ''' + convert(varchar(30),@dt2,120)+''''


引号
snowouldance 2009-11-20
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 hero__stone 的回复:]
SQL codeexec test'2009-11-12' ,'2009-11-16'
??
[/Quote]
exec test '2009-11-12' , '2009-11-16'
也是同样的报错
icelovey 2009-11-20
  • 打赏
  • 举报
回复
.
set @sqlstr ='select sn, convert(char(10),Test_Datetime,120) as test_datetime,result into trxtemp0 from ['
+ @tablename1 + '] where test_datetime between '''
+ convert(varchar(30),@dt1,120) + ''' and ''' + convert(varchar(30),@dt2,120)+''''
exec(@sqlstr)


这样看看
dawugui 2009-11-20
  • 打赏
  • 举报
回复
set @sqlstr ='select sn, convert(char(10),Test_Datetime,120) as test_datetime,result  into trxtemp0 from [' + @tablename1 + '] where test_datetime between ''' + convert(varchar(30),@dt1,120) + ''' and ''' + convert(varchar(30),@dt2,120) + ''''
exec(@sqlstr)
好汉坡 2009-11-20
  • 打赏
  • 举报
回复
exec test '2009-11-12' , '2009-11-16' 

??
bancxc 2009-11-20
  • 打赏
  • 举报
回复
set @sqlstr ='select sn, convert(char(10),Test_Datetime,120) as test_datetime,result into trxtemp0 from [' + @tablename1 + '] where test_datetime between ''' + convert(varchar(30),@dt1,120) + ''' and ''' + convert(varchar(30),@dt2,120)+''''
exec(@sqlstr)

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧