复制代码 代码如下:
DECLARE @MyName NVARCHAR(100)
DECLARE @FieldName SYSNAME = N'Name'
EXECUTE sp_executesql N'SELECT TOP 1 @OutputName = ['+ @FieldName +'] FROM [dbo].[Member]',
N'@OutputName NVARCHAR(100) OUTPUT',
@MyName OUTPUT;
SELECT @MyName
复制代码 代码如下:
DECLARE @MyName NVARCHAR(100)
DECLARE @FieldName SYSNAME = N'Name'
DECLARE @sql NVARCHAR(MAX) = N'SELECT TOP 1 @OutputName = ['+ @FieldName +'] FROM [dbo].[Member]'
EXECUTE sp_executesql @sql,
N'@OutputName NVARCHAR(100) OUTPUT',
@MyName OUTPUT;
SELECT @MyName
新闻热点
疑难解答