DECLARE @name NVARCHAR(30), @sql NVARCHAR(300)set @sql= N‘SELECT TOP 1 @n=EmpName from dbo.Emp‘
exec sp_executesql @sql, N‘@n nvarchar(30) output‘, @name output select @name
sp_executesql 的参数如果为字符型必须为NVARCHAR,或NCHAR类型,不能为VARCHAR或者CHAR类型,否则会报错
时间: 2024-11-10 08:16:07