根據表名和模板GGUID,得到表字段 及清單信息

if OBJECT_ID('sp_getTableColInfo','P') is not null drop proc sp_getTableColInfo  
go  
create proc sp_getTableColInfo  
@tablename varchar(128),  
@GGUID uniqueidentifier  
as  
Begin  
    with cte as  
    (  
        select   
            --字段名稱描述  
            b.desc0 as ColDesc,  
            --字段名稱  
            a.name as ColName,  
            --獲取字段類型  
            case a.xusertype 
						   when '167' then 'varchar('+LTRIM(a.length)+')'  
                           when '61' then 'datetime'  
                           when '36' then 'uniqueidentifier'  
                           when '56' then 'int'  
                           when '108' then 'numeric(38,2)'
                           when '34' then 'image'  
                           else ltrim(a.xusertype) end as [ColType],  
            --獲取清單信息  
            ListDetails=  
            (  
                select CID+':'+CHAR(9)+DESC0+CHAR(10)  
                from SMLSTD   
                where ltrim(LHGUID)=ltrim(b.CTRLID)  
                order by CID  
                for xml path('')  
            ),  
            --獲取是否允許爲空  
            case B.PNULL when 1 then '√'   
                         when 0 then ''  
                         else ltrim(b.PNULL) end as [Null],  
            --排序字段  
            B.Zorder  
        from syscolumns a  
        left join SMTMPD b on a.name=b.DID  
        where   
            a.id=OBJECT_ID(@tablename)  
            and b.GGUID=@GGUID  
          
    )  
    select   
        ColDesc,  
        ColName,  
        ColType,  
        [Null],  
        '',                 --預留  
        '',                 --預留  
        isnull(ListDetails,'')  
    from cte   
    order by ZORDER  
End  
go  
sp_getTableColInfo 
'CSEMPL_1',
'1e3411fa-7c0a-4034-b998-42362cb1d695'  


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章