这个参数怎样赋值???

starryearth 2012-09-11 04:05:07
Sql直接写死: buildingno in ('310000Fa001','310000Fe001')

在存储过程中使用参数:from EnergyDataSumByHour where BuildingNo in (@TargetValue) and EnergyType = @EType

问题:在执行存储过程时怎样给“@TargetValue”参数赋值???

@TargetValue='''310000Fa001,310000Fe001''' 这样赋值不对啊??? 怎么写才对???
...全文
102 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
汤姆克鲁斯 2012-09-13
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 的回复:]

必须要拼接SQL字符串吗??? string str = "310000Fa001,310000Fe001" 是不是就没有问题了。
[/Quote]
必须拼接。
xuam 2012-09-13
  • 打赏
  • 举报
回复
必须是:'310000Fa001','310000Fe001'
[Quote=引用 6 楼 的回复:]
必须要拼接SQL字符串吗??? string str = "310000Fa001,310000Fe001" 是不是就没有问题了。
[/Quote]
starryearth 2012-09-13
  • 打赏
  • 举报
回复
必须要拼接SQL字符串吗??? string str = "310000Fa001,310000Fe001" 是不是就没有问题了。
starrycheng 2012-09-12
  • 打赏
  • 举报
回复
大师,如果是“C#”传入参数, string str = "310000Fa001,310000Fe001" 是不是就没有问题了。
starryearth 2012-09-11
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

SQL code
exec('select * from EnergyDataSumByHour where BuildingNo in ('+ltrim(@TargetValue)+') and EnergyType ='+ltrim(@EType))
[/Quote]

大师,您这里拼接了“SQL”。存储过程直接写,不要拼接SQL参数应该怎样赋值???

也就是:

create proc test
as
select * from EnergyDataSumByHour where BuildingNo in (@TargetValue)


汤姆克鲁斯 2012-09-11
  • 打赏
  • 举报
回复
exec('select * from EnergyDataSumByHour where BuildingNo in ('+ltrim(@TargetValue)+') and EnergyType ='+ltrim(@EType))
發糞塗牆 2012-09-11
  • 打赏
  • 举报
回复
我也遇到过,没解决,后来把变量换成表变量传进去的。
starrycheng 2012-09-11
  • 打赏
  • 举报
回复
SQL字符串的拼接。

34,591

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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