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.
| Author |
Topic |
|
oob
Starting Member
15 Posts |
Posted - 2002-04-12 : 06:14:24
|
| I am working on an asp page that executes a sql string that uses the insert into statement and returns the @@Identity. One of the fields I need to insert is a name which may contain the apostrophe character(') in it.My sql statement in vbscript reads like this sSQL = "insert into Contact(ID, Name, Address) values (" nID & ",'" & sName & "','" & sAddress & "'"). Where sName could look something like 'J O' Brien'. My Insert into statement fails because of the extra apostrophe.Can anyone help me with this? |
|
|
timmy
Master Smack Fu Yak Hacker
1242 Posts |
Posted - 2002-04-12 : 06:45:44
|
| You can insert the apostrophe character into the table, but I've found that you need to use 2 apostrophe's in your string to end up with 1 in the new record.Just include this line of VBScript before you build your INSERT statement:sName = Replace(sName, "'", "''")This iterates throught the name string, replacing all ' (single apostrophe's) with '' (double), which SQL should understand. |
 |
|
|
setbasedisthetruepath
Used SQL Salesman
992 Posts |
Posted - 2002-04-12 : 08:34:30
|
| oob,you should use the quotename() function to escape the string.setBasedIsTheTruepath<O> |
 |
|
|
|
|
|