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
 General SQL Server Forums
 New to SQL Server Programming
 inserting to DB string with double ' instead of "

Author  Topic 

romeck
Starting Member

16 Posts

Posted - 2012-10-15 : 17:44:42
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

chadmat
The Chadinator

1974 Posts

Posted - 2012-10-15 : 17:51:26
INSERT INTO [AA].[AA].[RA] ([concode]) VALUES ('''''TK-BUD' )


-Chad
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2012-10-15 : 18:05:02
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.
Go to Top of Page

romeck
Starting Member

16 Posts

Posted - 2012-10-15 : 20:00:52
@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

52326 Posts

Posted - 2012-10-15 : 22:08:28
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

22864 Posts

Posted - 2012-10-16 : 10:28:36
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
   

- Advertisement -