| Author |
Topic |
|
snufse
Constraint Violating Yak Guru
469 Posts |
Posted - 2009-06-02 : 09:52:33
|
| If I have a string with value like "I'm the string" and I am trying to do an insert into a table I get error. Is there a way to insert this string without having to replace the "'" character? Could I use'''I'm the string''', is this correct? Thank you. |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-06-02 : 10:09:26
|
You can use a second single quote to mask it.I''m the string No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
snufse
Constraint Violating Yak Guru
469 Posts |
Posted - 2009-06-02 : 10:17:29
|
| I was thinking doing the whole string as I never know what user might enter, this why I will be covered. So is my approach correct? Thank you. |
 |
|
|
a.rameshk
Starting Member
19 Posts |
Posted - 2009-06-02 : 10:18:57
|
| Hi,You can insert the value by SELECT.So that you can exactly get value like I'am the string.CREATE TABLE STRINGS(StValue VARCHAR(50))GOinsert STRINGSSELECT SUBSTRING(('''I''am the string'''),1,16)goselect * from STRINGS |
 |
|
|
vision99
Starting Member
14 Posts |
Posted - 2009-06-02 : 10:22:51
|
| Hi, you can insert, In sqlserver Four single apostrophes equals one apostrophe output in the string. Eg. Carlito's look like this:'Carlito'+''''+'s Way'-Vision |
 |
|
|
snufse
Constraint Violating Yak Guru
469 Posts |
Posted - 2009-06-02 : 10:43:41
|
In fact I am reading hundreds of records from one table and programatically inserting into another table (insert into ... select from ...). In the string (character field) there might be any invalid character or any number of invalid characters (no way to anticipate), so I need to look at the whole string and not each position withing the string, this is what I had in mind.Exec('insert into mydataBase.dbo.JTABLE( report_state, report_year, name,Select zstate, ztyear, zname,from AS400SRV_MSDASQL.VGSYS400In this case "zname" could possible have any characters embedded. |
 |
|
|
kira
Starting Member
17 Posts |
Posted - 2009-06-02 : 10:53:04
|
| SET QUOTED_IDENTIFIER OFF |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-06-02 : 11:39:53
|
If the data already are inserted with single quote, you don't have to worry! E 12°55'05.63"N 56°04'39.26" |
 |
|
|
snufse
Constraint Violating Yak Guru
469 Posts |
Posted - 2009-06-02 : 12:01:13
|
| Here is a real example:Sql code:insert into .....values values(" ..... "," & "'" & zname & "'" & ","......Value of zname:Don'tRenders error: System.Data.OleDb.OleDbException: SQL0104: Token S was not valid. Valid tokens: ) ,.Cause . . . . . : A syntax error was detected at token S. Token S is not a valid token.Present work around:zname = zname.Replace("'", " ") |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-06-02 : 12:05:47
|
| use QUOTENAME() |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|