declare @s varchar(300)
set @s = 'select '
select @s = @s + A.name + ',' from syscolumns A, sysobjects B, systypes C
where A.id = B.id
and A.xtype = C.xtype
and B.name = 'a1'
and C.name <> 'image'
set @s = left(@s, len(@s) -1) + ' from a1'
select @s
exec (@s)
set @s = 'select '
select @s = @s + A.name + ',' from syscolumns A, sysobjects B, systypes C
where A.id = B.id
and A.xtype = C.xtype
and B.name = 'a1'
and C.name <> 'image'
set @s = left(@s, len(@s) -1) + ' from a1'
select @s
exec (@s)
set @str = ''
select @str = @str +','+ name
from syscolumns
where id=object_id('你的表') and objectproperty(id,'IsUserTable')=1
and name<>'照片'
set @str = 'select '+right(@str,len(@str)-1)+' from 你的表'
print @str
exec (@str)
加上良好的注释,维护程序也不是大问题
我个人认为,动态sql是不是在执行效率上有很大的问题,毕竟要逐个比较,
,如果哪一天要去掉其他的字段,那时候更会看出
灵活性的差异了
再次求问高手。