troubleshooting Question

SP parameters not evaluating

Avatar of vivekj2004
vivekj2004 asked on
Microsoft SQL Server 2005
4 Comments1 Solution233 ViewsLast Modified:
SP parameters are not evaluating in the following piece of code. In the print statement I can see that the parameters are not evaluating.
ALTER PROC TestProc
AS

DECLARE		@sql NVARCHAR(4000),
			@LocalDBTableName NVARCHAR(300),
			@TelDBTableName NVARCHAR(300),
			@LocalDBKeyName NVARCHAR(300),
			@TelDBKeyName NVARCHAR(300),
			@LocalDBFieldName NVARCHAR(300),
			@TelDBFieldName NVARCHAR(300),
------------------------------
--			@LocalDBKeyVal
--			@TelDBKeyVal
--			@
			
			@ErrorMsg NVARCHAR(2000)	
/*
SET @SQLQuery = 'SELECT * FROM tblEmployees WHERE EmployeeID = ' + 
CAST(@EmpID AS NVARCHAR(10))
/* Execute Transact-SQL String */
EXECUTE(@SQLQuery)  */

SET @LocalDBTableName='SDNTABLE'
SET @TelDBTableName='TelSDN'
SET @LocalDBKeyName='ListID'
SET @TelDBKeyName='SdnEntry_Id'
SET @LocalDBFieldName='FirstName'
SET @TelDBFieldName='FirstName'

 SET @sql = 'INSERT INTO OFACRecon_Report (@LocalDBTableName, @TelDBTableName, @LocalDBKeyName, @TelDBKeyName,
								 @LocalDBFieldName , @TelDBFieldName, 
								@LocalDBKeyName, @TelDBKeyName, @LocalDBFieldName , @TelDBFieldName)
SELECT '+'''@LocalDBTableName'',  ''@TelDBTableName'', ''@LocalDBKeyName'', ''@TelDBKeyName'', ''LocalDBFieldName'', ''TelDBFieldName'',
			r.@LocalDBKeyName,		
			t.@TelDBKeyName,
			ISNULL(r.@LocalDBFieldName,''''),		
			ISNULL(t.@TelDBFieldName,'''')
FROM TelSDN..@TelDBTableName t INNER JOIN OFAC..@LocalDBTableName r
ON (t.@TelDBKeyName=r.@LocalDBKeyName)
WHERE r.ListType=''OFAC''
		AND ISNULL(t.@TelDBFieldName,'''')<>ISNULL(r.@LocalDBFieldName,'''')'

----EXECUTE(@sql)

----EXEC TestProc


PRINT @sql
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros