查詢表、字段信息
阿新 • • 發佈:2018-05-10
查詢表字段信息
-----------------------------------------------------------------------------------------------------------------------------------------------------
use DSCSYS
go
DECLARE
@TableName nvarchar(100) = ‘COPTD‘
,@DataBase nvarchar(100) = ‘TOPLED2015‘
,@SQL nvarchar(4000)
,@Where nvarchar(4000) = ‘ where ‘
set @SQL = ‘select MD001,MD003,MD004,MD005,MD006,MD007 from DSCSYS..ADMMD where MD001 = ‘+ ‘‘‘‘ +
@TableName + ‘‘‘ and substring(MD003,1,2) = substring(‘‘‘ + @TableName + ‘‘‘,4,2)‘
exec(@SQL)
----------------------------------------------------------------------------------------------------------------------------------------------------
set @SQL =
STUFF((SELECT ‘,‘+ rtrim(MD003) + ‘ as ‘‘‘ + rtrim(MD004) + ‘‘‘‘
FROM ADMMD
where MD001 = @TableName and substring(MD003,1,2) = substring(@TableName,4,2)
FOR xml path(‘‘)),1,1,‘‘)
set @SQL =replace(‘select * from ‘,‘*‘,@SQL) + @DataBase + ‘..‘ + @TableName
exec(@SQL)
-------------------------------------------------------------------------------------------------------------------------------------------------------
查詢表、字段信息