通过表名字符串,返回表对象
本帖最后由 Foryour 于 2013-05-31 14:26:14 编辑
declare @tableName varchar(20)
Set @tablename = 'MyTable'
select * from f1 (@tableName)
f1(@tableName):通过name返回表的对象。
求f1???
------解决方案--------------------declare @tb varchar(20)
set @tb='MyTable'
declare @sql varchar(8000)
set @sql='SELECT * FROM '+@tb
exec (@sql)
------解决方案--------------------CREATE TABLE #TEMP
(
NAME VARCHAR(100),
TYPE_DESC VARCHAR(100)
)
INSERT INTO #TEMP
SELECT name,type_desc FROM sys.objects WHERE parent_object_id=OBJECT_ID('表名')
INSERT INTO #TEMP
SELECT name,type_desc FROM sys.indexes WHERE OBJECT_ID=OBJECT_ID('表名')
AND name IS NOT NULL
select * from #temp