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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

UPDATE Stored Procedure using Replace function

Status
Not open for further replies.

mrussell71

IS-IT--Management
Nov 28, 2001
20
0
0
US
I am using stored procedures to update an Access database. The majority of these procedures are DELETE queries and these run flawlessly. However, I am unable to get the right syntax for an UPDATE query.

sSQL = "CREATE PROCEDURE procEPCUpdateNGKPOUND " _
& "AS SELECT tblEPC SET " _
& "tblEPC.PartNo = Replace(tblEPC.PartNo, Chr(35), '') " _
& "WHERE((tblEPC.MfrCode)= 'NGK') "
CreateStoredProc(sSQL)

It doesn't like Replace. Any suggestions as to the right syntax would be greatly appreciated.
 
Replace is a VB function, not a SQL function.

Move your double-quotes to have VB evaluate it:
Code:
& "tblEPC.PartNo = '" & Replace(tblEPC.PartNo, Chr(35), '') & "' " _

If your PartNo field in the database is a nchar or nvarchar datatype you should also put an "N" in front of the single-quote to make sure that SQL understands that it's a Unicode value:
Code:
& "tblEPC.PartNo = N'" & Replace(tblEPC.PartNo, Chr(35), '') & "' " _

You can also avoid using the Replace function altogether by going through ADO parameters - they will take care of replacing not only the single-quotes, but double-quotes too (they also cause problems for the database).

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top