Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 syntax error help

Author  Topic 

smccreadie
Aged Yak Warrior

505 Posts

Posted - 2002-03-08 : 15:05:41
Here's the procedure for pulling up a patient from table:


CREATE PROCEDURE getpatient_byln


@ln varchar(50)

AS

Select visit_id, last_name, first_name, birthdate, sex, area, room_bed, admit_date, weight_kg, medical_service, attending_doctor

from TBL_ADT

where last_name like @ln+'%'

order by last_name, first_name


This works great usually. However if you have a last name that is a SQL keyword like Cross, it bombs with this error:

Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near the keyword 'cross'.

/pharmdoc/getpatient/getpatient2.asp, line 51


I tried putting some single quotes around the entry but it still fails. Any ideas how to fix this?



setbasedisthetruepath
Used SQL Salesman

992 Posts

Posted - 2002-03-08 : 15:11:43
use quotename().

This will work in your specific case and you might consider using it generally also.

Go to Top of Page
   

- Advertisement -