存储过程当中的问题??

ingernew 2003-08-19 01:00:47
@Store nvarchar(550)
AS

SELECT * FROM BCParts
where Store in (@Store)

请问这个变量怎么传值!如果我传单个的值比如
@Store="FPP"就可以得到结果,而我使用@Store="'FPP','FPG'"和@Store="FPP,FPG"也得不到结果,这是为什么?我该怎样做?
另外用in这种查询方式是不是处理的时间会更长。有没有更好的方法?
...全文
30 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
ingernew 2003-08-20
  • 打赏
  • 举报
回复
我是想传值进来的不想带外面那层引号也就是这样的格试
FPP','FPG
而外层那个单引号在存储过程中加入!

因为我用的是下拉菜单传值(通用的控件),如果每个都带外面那引号就很不方便了!
zjcxc 2003-08-20
  • 打赏
  • 举报
回复
你是在那里写语句的?

下面的语句在查询分析器中测试正常
declare @Store varchar(20),@csql varchar(1000)
set Store='''FPP'',''FPG'''
set @cSQL='Select * FROM BCParts where Store in ('+@Store+')'
EXEC (@cSQL)
ingernew 2003-08-19
  • 打赏
  • 举报
回复
太高兴遇到救星了 但!
为什么发生了第 2 行: ',' 附近有语法错误。
我用的值是@Store="FPP','FPG"
zjcxc 2003-08-19
  • 打赏
  • 举报
回复

set @cSQL='Select * FROM BCParts where Store in ('''+@Store+''')'
EXEC (@cSQL)
ingernew 2003-08-19
  • 打赏
  • 举报
回复
cysh(cysh) 您好!用这句
set @cSQL='Select * FROM BCParts where Store in ('+@Store+')'
EXEC (@cSQL)
我要在@Store外面怎么加上引号也就是
Store in (' '+@Store+'')'
但用这种方法不行的!


cysh 2003-08-19
  • 打赏
  • 举报
回复
用charindex肯定不行,会出现意想不到的结果,用动态SQL吧。
CrazyFor 2003-08-19
  • 打赏
  • 举报
回复
或者:

@Store nvarchar(550)
AS

exec('SELECT * FROM BCParts
where Store in ('+@Store+')')

ingernew(东东),charindex(','''+Store+''',' , ','+@Store+',') >0就是搜索Store是不是@store的中被包含.

jntvip 2003-08-19
  • 打赏
  • 举报
回复
declare @cSQL varchar(200),
set @cSQL='Select * FROM BCParts where Store in ('+@Store+')'
EXEC (@cSQL)
ingernew 2003-08-19
  • 打赏
  • 举报
回复
CrazyFor(太阳下山明朝依旧爬上来)
我没有理解你的意思!!为什么这样
(','''+Store+''',' , ','+@Store+',') >0
CrazyFor 2003-08-19
  • 打赏
  • 举报
回复
@Store nvarchar(550)
AS

SELECT * FROM BCParts
where charindex(','''+Store+''',' , ','+@Store+',') >0
....

22,207

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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