直接Select isnull(工程名称,'')+isnull(工程地点,'')+isnull(工程造价,'')
+isnull(人员,'')+.......
From Table 是不行的哦,比如工程地点是空那么显示
工程名称 空列 工程造价 人员
东路工程 空值 2500 张三
估计还是得用我的动态指定列名
declare @tmp varchar(100), --临时记录需要查询字段串
@gc varchar(20) --每条记录空的字段不一样,只能一条判断,暂且已不重复工程名称做条件
set @gc='东路工程' --谢塘改造工程 东路工程
set @tmp='工程名称'
if (select IsNull(工程地点,'') from a where 工程名称=@gc)<>''
set @tmp=@tmp+',工程地点'
if (select IsNull(工程造价,'') from a where 工程名称=@gc)<>''
set @tmp=@tmp+',工程造价'
if (select IsNull(工程人员,'') from a where 工程名称=@gc)<>''
set @tmp=@tmp+',工程人员'
if (select IsNull(设备,'') from a where 工程名称=@gc)<>''
set @tmp=@tmp+',设备'
if (select IsNull(备注,'') from a where 工程名称=@gc)<>''
set @tmp=@tmp+',备注'
--后面还有字段自己顺着加判断。。。。
exec('select '+@tmp+' from a where 工程名称='''+@gc+'''')
declare @tmp varchar(100), --临时记录需要查询字段串
@gc varchar(20) --每条记录空的字段不一样,只能一条判断,暂且已不重复工程名称做条件
set @gc='东路工程' --谢塘改造工程 东路工程
set @tmp='工程名称'
if (select IsNull(工程地点,'') from a where 工程名称=@gc)<>''
set @tmp=@tmp+',工程地点'
if (select IsNull(工程造价,'') from a where 工程名称=@gc)<>''
set @tmp=@tmp+',工程造价'
if (select IsNull(工程人员,'') from a where 工程名称=@gc)<>''
set @tmp=@tmp+',工程人员'
if (select IsNull(设备,'') from a where 工程名称=@gc)<>''
set @tmp=@tmp+',设备'
if (select IsNull(备注,'') from a where 工程名称=@gc)<>''
set @tmp=@tmp+',备注'
--后面还有字段自己顺着加判断。。。。
exec('select '+@tmp+' from a where 工程名称='''+@gc+'''')