sql查询列名含有某些字符的列
sql中表A有很多列,列名为scodeA1A2AOPEN1A3A4AOPEN2等等,现在我想查询出scode和列名含open的列,不知如何写普通sql查询语句,不写存储过...
sql中表A有很多列,列名为 scode A1 A2 AOPEN1 A3 A4 AOPEN2等等,现在我想查询出scode和列名含open的列,不知如何写普通sql查询语句,不写存储过程
展开
2个回答
展开全部
一句话似乎不太容易搞定,以下是我写的一段sql语句
declare @name varchar(100),@sql varchar(1000)
set @name=''
select @name=@name+','+name from syscolumns where id=(select id from sysobjects where name='A')and (name like'%open%' or name=''scode)
set @name=stuff(@name,1,1,'')
set @sql='select '+@name+' from ieos01h'
exec(@sql)
declare @name varchar(100),@sql varchar(1000)
set @name=''
select @name=@name+','+name from syscolumns where id=(select id from sysobjects where name='A')and (name like'%open%' or name=''scode)
set @name=stuff(@name,1,1,'')
set @sql='select '+@name+' from ieos01h'
exec(@sql)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询