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 2005 Forums
 Transact-SQL (2005)
 [Resolved] Insert gives error

Author  Topic 

snufse
Constraint Violating Yak Guru

469 Posts

Posted - 2008-10-13 : 15:27:21
Trying to insert a record using variables from a data set. Get error on variable myRow.Item(63).

insert into rjadevlib.f5514ar (f1, f2, f3) " values(" & "'" myRow.Item(63) & "'" & "," & "'" & myRow.Item(64) & "'" & "," & "'" & myRow.Item(65) & "'" & ")"


The content is:

insert into rjadevlib.f5514ar(f1, f2, f3) values('101 Sansbury's Way ','West Palm Beach ','Fl')


SQL0104: Token S was not valid. Valid tokens: ) ,.
Cause . . . . . : A syntax error was detected at token S. Token S is not a valid token.

Is there a way around this? Thank you

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2008-10-13 : 15:33:52
insert into rjadevlib.f5514ar(f1, f2, f3) values('101 Sansbury''s Way ','West Palm Beach ','Fl')
Go to Top of Page

snufse
Constraint Violating Yak Guru

469 Posts

Posted - 2008-10-13 : 16:58:01
I need to capture and set this reading the variable "myRow.Item(63)". Is there a way to do that?
Go to Top of Page

hanbingl
Aged Yak Warrior

652 Posts

Posted - 2008-10-13 : 17:12:27
REPLACE(MYROW.ITEM(63),'''','''''')
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2008-10-13 : 17:12:57
I think you're building the sql-statement in VB or something like VB.
Why don't you use stringreplace-function and do the replace '(single quote) by ''(2 single quote)?

Webfred

Planning replaces chance by mistake
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-10-14 : 03:40:35
See how single quotes work
http://sqlblogcasts.com/blogs/madhivanan/archive/2008/02/19/understanding-single-quotes.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

snufse
Constraint Violating Yak Guru

469 Posts

Posted - 2008-10-14 : 07:54:42
Thank you guys, I appreciate the response from each of you. Now I have it solved.....
Go to Top of Page
   

- Advertisement -