declare @a varchar(20),@b varchar(20),@tmp int,@str varchar(100)
select @a = '1,3,5,7',@b = '4,5,6,7',@tmp=0,@str=''while @tmp<=1000
begin
if charindex(','+convert(varchar,@tmp)+',',','+@a+','+@b+',')>0
set @str=@str+','+convert(varchar,@tmp)
set @tmp=@tmp+1
endselect stuff(@str,1,1,'')--结果
/*
----------------------------
1,3,4,5,6,7(所影响的行数为 1 行)
*/
select @a = '1,3,5,7',@b = '4,5,6,7',@tmp=0,@str=''while @tmp<=1000
begin
if charindex(','+convert(varchar,@tmp)+',',','+@a+','+@b+',')>0
set @str=@str+','+convert(varchar,@tmp)
set @tmp=@tmp+1
endselect stuff(@str,1,1,'')--结果
/*
----------------------------
1,3,4,5,6,7(所影响的行数为 1 行)
*/
解决方案 »
- SQL 中建立一个唯读的帐户,用户选择那一个类型呢
- 请问,关于SQL SERVER的问题
- 不会表达,看帖子内容吧!~~在线等,谢谢!
- bcp文件导入数据库时出现乱码!急!急!急!急!
- 帮忙写一个order by 语句,非常感谢
- awaiting command
- 如何将txt文件导入到带自增(标识)字段的sqlserver表中?
- 如何把一台服务器上的数据自动备份到另一台服务器上
- 谁知道access的mdb文件转为exe文件办法
- 送分:什么时候数据库会写硬盘?
- ●●高分悬赏●●:执行存储过程提示:attempted to return a status of NULL, which is not allowed. A status of 0 will be returned i
- 合并查询
可以用ASCII()和SUBSTRING()函数把数字一个一个地截出来,然后对数字进行排序。
排序完成后,再存到@c中就可以了。
select @a = '1,3,15,7',@b = '4,5,6,7',@tmp=0,@str=''select @tmp = charindex(',',@b)while (@tmp > 0 )
begin
select @str = left(@b,@tmp-1)
select @b = stuff(@b,1,@tmp,'')
select @tmp = charindex(',',@b)
if charindex(','+@str+',',','+@a+',') <= 0
select @a = @a + ',' + @strend
select @a
select @a = '1,3,15,7',@b = '4,5,6,7',@tmp=0,@str=''select @tmp = charindex(',',@b)while (@tmp > 0 )
begin
select @str = left(@b,@tmp-1)
select @b = stuff(@b,1,@tmp,'')
select @tmp = charindex(',',@b)
if charindex(','+@str+',',','+@a+',') <= 0
select @a = @a + ',' + @strendif charindex(','+@b+',',','+@a+',') <= 0
select @a = @a + ',' + @bselect @a