Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: Single Quotes are a part of the Data Literal in an SQL statement


Message #1 by "Ajax" <ajax@i...> on Wed, 4 Oct 2000 07:42:16 +0530
Hi Listers,



I have had this problem with SQL based RDBMS for a long time now. Are there

any solutions prescribed?



In case of text fields, represented by char or varchar in RDBMS, it gives an

error if the the data literal (text field value) contains a symbol ('). The

"single quote" is used is random without much thought to represent values

like "O'Brien", "Ajax's House" etc.



SQL Server states that the insert statement needs to be restructured like

either :



1. Insert into <TableName> (<Fieldname>) values ("O'Brien")

	[the values of the text field are included in DOUBLE QUOTES]

	or

2. Insert into <TableName> (<Fieldname>) values ('O''Brien')

	[the values of text field are searched for the existence of the charater

(') and replaced with the charectors (''), typically using the replace() fn

in VB]



Now while the first option seems to be easy in operation, an sql command

structured in this format gives the error "Invalid Column Name O'Brien".

This is because unfortunately a similar scheme (ie. double quoted

identifiers) are used by SQL Server to mark Objects whose names are reserve

words like (select, date, year etc))



The second example works well but there arises a need to search and replace

the whole string (could be a Text (memo) field), which is expensive as in

time & resource consuming, before it is included in the SQL query.



Please advice as to the possibilities other than the above in this matter.



Ajax..





-------------------------------------------------------

If it ain't what it looks like It ain't worth it

WYSIWYG Mantra

-------------------------------------------------------



Message #2 by "Benny" <benny@t...> on Wed, 11 Oct 2000 12:16:43 +0200
Hi Ajax,



If you fill the memo field via a form field you could add the extra qoute in

your validatation routines on your client.



Benny




  Return to Index