是否可以在SQL中执行类似的操作?
DECLARE @t Nvarchar(50)
SET @t = 'SELECT * FROM KIN_PHON'
execute @t --??
答案 0 :(得分: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;