SQL Server 7
Hello,
I'm trying to write a dynamic SQL statement to run in my stored procedure. For now, I'm just trying to concantanize (sp?) and print the statement, but am having issues with the apostrophe junk. Any help would be greatly appreciated!!!
DECLARE @SQL NVARCHAR(2000)
DECLARE @DB NVARCHAR(20)
DECLARE @EMPLOYID NVARCHAR(20)
SET @DB = 'AA'
SET @EMPLOYID = '0101'
SET @SQL = 'UPDATE #T1 A, '+@DB+'.DBO.UPR00102 B
SET A.ADDRESS1 = B.ADDRESS1, A.ADDRESS2 = B.ADDRESS2, A.ADDRESS3 = B.ADDRESS3, A.CITY = B.CITY, A.STATE = B.STATE, A.ZIP = B.ZIPCODE, A.COUNTRY = B.COUNTRY,
A.PHONE = B.PHONE1, A.OTHERPHONE1 = B.PHONE2, A.OTHERPHONE2 = B.PHONE3,
A.FAX = B.FAX
--Problem seems to be on this line:
WHERE A.EMPLOYID = ''' +@EMPLOYID+ ''' AND A.DB = ''' +@DB ''' AND DEFECT = ''GP Match in Rolodex''
PRINT @SQL
...I either get "Incorrect syntax near ''AND DEFECT..." or "Unclosed quotation mark..." If anyone's a concatenating expert your help is greatly appreciated!!!
Thanks,
Jason
Hello,
I'm trying to write a dynamic SQL statement to run in my stored procedure. For now, I'm just trying to concantanize (sp?) and print the statement, but am having issues with the apostrophe junk. Any help would be greatly appreciated!!!
DECLARE @SQL NVARCHAR(2000)
DECLARE @DB NVARCHAR(20)
DECLARE @EMPLOYID NVARCHAR(20)
SET @DB = 'AA'
SET @EMPLOYID = '0101'
SET @SQL = 'UPDATE #T1 A, '+@DB+'.DBO.UPR00102 B
SET A.ADDRESS1 = B.ADDRESS1, A.ADDRESS2 = B.ADDRESS2, A.ADDRESS3 = B.ADDRESS3, A.CITY = B.CITY, A.STATE = B.STATE, A.ZIP = B.ZIPCODE, A.COUNTRY = B.COUNTRY,
A.PHONE = B.PHONE1, A.OTHERPHONE1 = B.PHONE2, A.OTHERPHONE2 = B.PHONE3,
A.FAX = B.FAX
--Problem seems to be on this line:
WHERE A.EMPLOYID = ''' +@EMPLOYID+ ''' AND A.DB = ''' +@DB ''' AND DEFECT = ''GP Match in Rolodex''
PRINT @SQL
...I either get "Incorrect syntax near ''AND DEFECT..." or "Unclosed quotation mark..." If anyone's a concatenating expert your help is greatly appreciated!!!
Thanks,
Jason