QKY(Study)

博客园 首页 新随笔 联系 订阅 管理

Create Procedure DBO.Pro_GetTableData @StrTableName sysname
AS
declare @TableName sysname
declare @TableId int

select @TableName=@StrTableName
select @TableId=id from sysobjects where name=@TableName
    if (@Tableid<>0)
    begin
        Declare @SqlStr Varchar(8000)
        set @SqlStr='select '
        select @SqlStr=@SqlStr+name+' ['+name+'] '+isnull((select ',' from dbo.syscolumns where id=@TableId and colid=A.colid+1),'')
        from dbo.syscolumns AS A where id=@TableId
        order by colid
        select @SqlStr=@SqlStr+' from '+@TableName
        exec (@SqlStr)
    end
    else
    return

posted on 2006-09-12 21:39  千孔衣  阅读(302)  评论(0)    收藏  举报