I'm working with a SQL stored procedure and dynamic SQL. When I try to debug everything works fine, up until when I'm printing my @columnName.
this is the part of the code that's causing trouble:
DECLARE @query NVARCHAR(2000)
DECLARE @columnName NVARCHAR(250)
SELECT @query = 'SELECT myTable.value FROM myTable WHERE myConditions'
EXECUTE sp_executesql @query, N'@columnName NVARCHAR(30) OUTPUT', @columnName OUTPUT
PRINT N'query='+@query
set @query = ''
PRINT N'query after reset='+@query
PRINT N'columnName='+@columnName
PRINT N'any other message'
Select @query = 'SELECT myValues AS '''+@columnName+''',
FROM myTable2
WHERE myConditions';
EXEC(@query);
This is the output messages:
query=SELECT myTable.value FROM myTable WHERE myConditions
query after reset=
any other message
So, where is my columnName= output?
EDIT
SQL Version: Microsoft SQL Server 2012 - 11.0.2100.60 (X64) Feb 10 2012 19:39:15 Copyright (c) Microsoft Corporation Standard Edition (64-bit) on Windows NT 6.1 (Build 7601: Service Pack 1) (Hypervisor)
sql-server-2012- that's where you should specify these kinds of things.... - marc_s