1

是否可以在 SQL 中做类似的事情?

DECLARE @t Nvarchar(50)

SET @t = 'SELECT * FROM KIN_PHON'

execute @t  --??
4

1 回答 1

1

使用exec

DECLARE @t Nvarchar(50)
SET @t = 'SELECT * FROM KIN_PHON'
exec (@t)

或使用参数sp_executesql

declare @sql nvarchar(max)
set @sql = 'select * from YourTable where ID = @ID'
execute sp_executesql @sql, N'@ID int', @ID = 42;
于 2013-03-29T14:59:35.073 回答