declare @s varchar(8000)
set @s=''
select @s=@s+','+cast(id as varchar)
table where id=1 or id=2 or id=3
select 结果=substring(@s,2,8000)
set @s=''
select @s=@s+','+cast(id as varchar)
table where id=1 or id=2 or id=3
select 结果=substring(@s,2,8000)
set @Ids=''
select @Ids=@Ids+id+',' from
(
select 1 as id
union all
select 2 as id
union all
select 3 as id
) as x left join table1 t
on x.id=t.id
where t.id is nullif @ids<>''
set @ids=left(@ids,len(@ids)-1)print @ids
set @str=''select @str=@str+','+cast(ID as varchar)
from Table
where not(id=1 or id=2 or id=3)select @str
set @str=''select @str=@str+','+cast(ID as varchar)
from Table
where not(id=1 or id=2 or id=3)select substring(@str,2,8000)
set @Ids=''
select @Ids=@Ids+cast(id as varchar(10))+',' from
(
select 1 as id
union all
select 2 as id
union all
select 3 as id
) as x left join table1 t
on x.id=t.id
where t.id is nullif @ids<>''
set @ids=left(@ids,len(@ids)-1)print @ids
因为这样会出来很多不需要的数据,这样会拉出来我查询条件中没有但是表中有的所有数据。
CCEO(CSDN的CEO??) 的方法不好实现!?