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+'''')