读书人

SQL查询数据为空的列不显示,该如何处理

发布时间: 2012-06-16 20:34:32 作者: rapoo

SQL查询数据为空的列不显示


源地址:http://zhidao.baidu.com/question/340437545.html?seed=0

无意当中看到这个问题,自己没什么好的方法,故求大神。




[解决办法]
以前讨论过这个 用动态拼接。
[解决办法]

SQL code
declare @str varcahr(100)='select id'if(select col1 from tb where id=@id) is not null set @str=@str+',col1'if(select col2 from tb where id=@id) is not null set @str=@str+',col3'...exec(@str+' where id='''+@id+'') 

读书人网 >SQL Server

热点推荐