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

zy32002 2011-11-10 02:47:38


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

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


...全文
1869 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
秦宇升 2012-06-15
  • 打赏
  • 举报
回复
嗯 不错 不错
zy32002 2011-11-10
  • 打赏
  • 举报
回复
谢谢 2位 学习了
结贴
zy32002 2011-11-10
  • 打赏
  • 举报
回复
declare @str varchar(100)='select id',
@id int=1;
if(select col1 from ccc where id=@id) is not null
set @str=@str+',col1'
if(select col2 from ccc where id=@id) is not null
set @str=@str+',col2'
if(select col3 from ccc where id=@id) is not null
set @str=@str+',col3'
--print @str
exec(@str+' from ccc where id='''+@id+'''')
快溜 2011-11-10
  • 打赏
  • 举报
回复
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+'')
zy32002 2011-11-10
  • 打赏
  • 举报
回复
我只想知道sql是怎么写 在程序里实现谁都会
快溜 2011-11-10
  • 打赏
  • 举报
回复
笨办法就是拼字符串,其实你可以在程序里动态绑定数据控件
zy32002 2011-11-10
  • 打赏
  • 举报
回复
哦 怎么写?? 求链接
--小F-- 2011-11-10
  • 打赏
  • 举报
回复
以前讨论过这个 用动态拼接。

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧