SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 inserting to DB string with double ' instead of "
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

romeck
Starting Member

16 Posts

Posted - 10/15/2012 :  17:44:42  Show Profile  Reply with Quote
Hi there i have strange thing , my clients emploee sometimes puts double ' instead of " into contractors name .

if i use insert TSQL ie:

INSERT INTO [AA].[AA].[RA]  ([concode])  VALUES  ('''TK-BUD' )


then in the end in DB in concod field, there is only 'TK-BUD instead of ''TK-BUD . Now i cant compare it to data which is inserted via some soft (which can somehow insert '' correctly ) . So the question is what i have to do to insert '' correctly into DB.

using :

declare @xxx as varchar(50)
set @xxx='''TK-BUD'
INSERT INTO [AA].[AA].[RA]  ([concode])  VALUES  (@xxx)


also do not help .

THQ

Edited by - romeck on 10/15/2012 17:50:49

chadmat
The Chadinator

USA
1974 Posts

Posted - 10/15/2012 :  17:51:26  Show Profile  Visit chadmat's Homepage  Reply with Quote
INSERT INTO [AA].[AA].[RA] ([concode]) VALUES ('''''TK-BUD' )


-Chad
Go to Top of Page

Lamprey
Flowing Fount of Yak Knowledge

4612 Posts

Posted - 10/15/2012 :  18:05:02  Show Profile  Reply with Quote
Another alternative that I recomend is to use the CHAR function:
INSERT INTO [AA].[AA].[RA] ([concode]) VALUES (CHAR(39) + CHAR(39) + 'TK-BUD' )
EDIT: Doubled up the single quote.

Edited by - Lamprey on 10/15/2012 18:06:40
Go to Top of Page

romeck
Starting Member

16 Posts

Posted - 10/15/2012 :  20:00:52  Show Profile  Reply with Quote
@chadmat - no that wont work, couses error

@Lamprey - :) yes thats work thanks (although i was expecting that simplier way exist couse i have to create function that have to analyse char after char in the 40 char long string which i presume is a bit not efficient , many many "if"s couse of ' could be first could be last or could be multiplied :) )
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 10/15/2012 :  22:08:28  Show Profile  Reply with Quote
quote:
Originally posted by romeck

@chadmat - no that wont work, couses error

@Lamprey - :) yes thats work thanks (although i was expecting that simplier way exist couse i have to create function that have to analyse char after char in the 40 char long string which i presume is a bit not efficient , many many "if"s couse of ' could be first could be last or could be multiplied :) )



it will work

see


declare @test table
(
val varchar(30)
)

insert @test values('''''test'),(char(39) + char(39) + 'test')

select * from @test


output
----------------------------
val
------------------------------
''test
''test



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22744 Posts

Posted - 10/16/2012 :  10:28:36  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
Also read this post
http://beyondrelational.com/modules/2/blogs/70/posts/10827/understanding-single-quotes.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000