生成view的描述字段列表

declare @table nvarchar(50);
declare @field_list nvarchar(max);
set @table = N'vwMaterial';
set @field_list = N'';


SELECT      u.name + '.' + t.name AS [table],
            cast(td.value as nvarchar(100)) AS [table_desc],
            cast(c.name as nvarchar(100))  AS [column],
            cast(cd.value as nvarchar(100))  AS [column_desc],
            c.colorder
            into #temp
FROM        sysobjects t
INNER JOIN  sysusers u
    ON      u.uid = t.uid
LEFT OUTER JOIN sys.extended_properties td
    ON      td.major_id = t.id
    AND     td.minor_id = 0
    AND     td.name = 'MS_Description'
INNER JOIN  syscolumns c
    ON      c.id = t.id
LEFT OUTER JOIN sys.extended_properties cd
    ON      cd.major_id = c.id
    AND     cd.minor_id = c.colid
    AND     cd.name = 'MS_Description'
WHERE t.name = @table
ORDER BY  [table],colorder;

select @field_list = @field_list + ',[' + cast([column] as nvarchar(100)) + '] as [' + cast(column_desc as nvarchar(100))  + ']' + NCHAR(10) from 
#temp;

set @field_list = 'select '  + SUBSTRING(@field_list ,2 ,LEN(@field_list)-1) + ' from dbo.' + @table;
select @field_list;

drop table #temp;

 

转载于:https://www.cnblogs.com/coolyylu/p/8136714.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值