sql de1

oceantang 2008-09-17 06:38:24
我想把 'staff_id in('F80D30','E53D6B','FC2E0E','006204','006117','006213','006220','ECFAB0','006216')'
变成 'staff_id
in(''F80D30'',''E53D6B'',''FC2E0E'',''006204'',''006117'',''006213'',''006220'',''ECFAB0'',''006216'')'

怎么做?
...全文
110 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
oceantang 2008-09-17
  • 打赏
  • 举报
回复
真正的意思是程序里得到的值是: @变量= and staff_id in('F80D30','E53D6B','FC2E0E','006204','006117','006213','006220','ECFAB0','006216')
现在想调用
create procedure Owner_Distribution_Info(@staffinfo varchar(500),@total int,@amountcount int)
as
begin
if object_id('c_dzh_assigninfo') is null
begin
create table c_dzh_assigninfo (cur_staff char(6),assigncount int default(0))
end
else
begin
truncate table c_dzh_assigninfo
end
declare @sql1 varchar(500)
set @sql1=
'insert into c_dzh_assigninfo (cur_staff) select staff_id from staff where 1=1 '+@staffinfo+''
exec(@sql1)
declare @sql varchar(8000),@midvar int
set @sql='update c_dzh_assigninfo set assigncount='+rtrim(@total/@amountcount)+' where cur_staff in(select top '+rtrim(@amountcount)+' cur_staff from c_dzh_assigninfo)'
exec(@sql)
if(rtrim(@total-(@total/@amountcount)*@amountcount)>=1 and @total-(@total/@amountcount)*@amountcount<@amountcount)
begin
set @midvar=floor((@total-(@total/@amountcount)*@amountcount)/@amountcount+1)
end
set @sql='update c_dzh_assigninfo set assigncount=assigncount+'+rtrim(ltrim(@midvar))+' where
cur_staff in(select top '+rtrim(@total-(@total/@amountcount)*@amountcount)+' cur_staff from c_dzh_assigninfo)'
exec(@sql)
end
这个存储过程。 现在想把@变量作为Distribution的第一个变量。否则就现在这个@变量传到这个存储过程的话在执行 set @sql1=
'insert into c_dzh_assigninfo (cur_staff) select staff_id from staff where 1=1 '+@staffinfo+''
exec(@sql1)会报错。所以需要转换成 ' and staff_id
in(''F80D30'',''E53D6B'',''FC2E0E'',''006204'',''006117'',''006213'',''006220'',''ECFAB0'',''006216'')' 大家有什么办法吗?
fcuandy 2008-09-17
  • 打赏
  • 举报
回复
都不明白你要什么,当然就答不明白了。

不知道你说的那个值是前台程序中的值,还是sql中的值还是表达式

理解有不同,那么你的'也就会被理解为不同。 '可能就是',也可能是''
oceantang 2008-09-17
  • 打赏
  • 举报
回复
还没有满意的答案!
fcuandy 2008-09-17
  • 打赏
  • 举报
回复
..
CN_SQL 2008-09-17
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 oceantang 的回复:]
意思就是想把 'staff_id in('F80D30','E53D6B','FC2E0E','006204','006117','006213','006220','ECFAB0','006216')'
变成 'staff_id
in(''F80D30'',''E53D6B'',''FC2E0E'',''006204'',''006117'',''006213'',''006220'',''ECFAB0'',''006216'')'

用SQL怎么做?
[/Quote]

declare @s varchar(300)

set @s = '''staff_id in(''F80D30'',''E53D6B'',''FC2E0E'',''006204'',''006117'',''006213'',''006220'',''ECFAB0'',''006216'')'''

print @s

set @s = '''staff_id' + char(10)
+ replace(replace(replace(replace(@s,'staff_id ',''),'(''','('''''),''')',''''')'),''',''',''''',''''')
print '--------------------------------------------------------'

print @s

/**
'staff_id in('F80D30','E53D6B','FC2E0E','006204','006117','006213','006220','ECFAB0','006216')'
--------------------------------------------------------
'staff_id
'in(''F80D30'',''E53D6B'',''FC2E0E'',''006204'',''006117'',''006213'',''006220'',''ECFAB0'',''006216'')'
**/
oceantang 2008-09-17
  • 打赏
  • 举报
回复
意思就是想把 'staff_id in('F80D30','E53D6B','FC2E0E','006204','006117','006213','006220','ECFAB0','006216')'
变成 'staff_id
in(''F80D30'',''E53D6B'',''FC2E0E'',''006204'',''006117'',''006213'',''006220'',''ECFAB0'',''006216'')'

用SQL怎么做?
nzperfect 2008-09-17
  • 打赏
  • 举报
回复

能说明白吗?
oceantang 2008-09-17
  • 打赏
  • 举报
回复
晕倒
看清我的题目了嘛???用SQL语句写。
anovice 2008-09-17
  • 打赏
  • 举报
回复
什么意思
是不是这样

staff_id in('''F80D30''','''E53D6B''','''FC2E0E''','''006204''','''006117''','''006213''','''006220''','''ECFAB0''','''006216''')'
113244 2008-09-17
  • 打赏
  • 举报
回复
转义符、。

22,302

社区成员

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

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