I have got an issue with Dynamic Variable Parsing incorrectly and I don't know a way around it.
Here is an example:
DECLARE @tableName varchar(20),
@columnName varchar(20),
@prompt varchar(20)
DECLARE @dynSQL varchar(500)
set @tableName = '[A1-ExciseESN]'
set @columnName = '[Anode Excise ESN (A1)]'
@dynSQL = 'INSERT INTO ' + @tableName +'
([trav num], '+@columnName+')
Select [trav num], '+@columnName+'
FROM [temprmi$] t1
PIVOT(min([Lvl1 Trace Data])
FOR [Prompt Text] IN ('+@columnName+'
)
) AS PVTTable
where '+@columnName+' is not null and [trav num] not in (select [trav num] from '+@tableName+')'
print @dynSQL
Here is the output of the print @dynSQL
INSERT INTO [A1-ExciseESN]
([trav num], [Anode Excise ESN (A)
Select [trav num], [Anode Excise ESN (A
FROM [temprmi$] t1
PIVOT(min([Lvl1 Trace Data])
FOR [Prompt Text] IN ([Anode Excise ESN (A
)
) AS PVTTable
where [Anode Excise ESN (A is not null and [trav num] not in (select [trav num] from [A1-ExciseESN])
I've tried several methods but can't seem to make it work. Thanks in advance for the help!