Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Quotation Headache! 1

Status
Not open for further replies.

dBjason

Programmer
Mar 25, 2005
355
US
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
 
I see 2 items
Code:
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 
	WHERE A.EMPLOYID = ''' +@EMPLOYID+ ''' AND A.DB = ''' +@DB+''' AND DEFECT = ''GP Match in Rolodex'''

SELECT @SQL
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top