all groups > sql server programming > november 2006 >
You're in the

sql server programming

group:

inserting a single quote


inserting a single quote Billy
11/8/2006 11:56:02 PM
sql server programming:
I have a character field I am exporting from the database. This character
field holds order numbers with leading 0s...so 0000345. I would like to know
how I can export this field, but woith adding a single quote to the front of
the field...so 0000345 is exported as '0000345.

Many thx
Re: inserting a single quote Uri Dimant
11/9/2006 12:00:00 AM
Billy
create table #tmp(c varchar(20))

insert into #tmp values ('''0003')

select * from #tmp


[quoted text, click to view]

Re: inserting a single quote Uri Dimant
11/9/2006 12:00:00 AM
Billy
create table #tmp(c varchar(20))
insert into #tmp values ('0003')
insert into #tmp values ('0004')
insert into #tmp values ('0005')

--you can either update or format the column's data

select *, ''''+c from #tmp
--or
update #tmp set c=''''+c

select * from #tmp


[quoted text, click to view]

RE: inserting a single quote Krishnakumar S
11/9/2006 12:14:02 AM
Just append another single quote as escape sequence. For example, to insert
'0000345,
INSERT INTO Table1 VALUES ('''0000345'), i.e, ''0000345 enclosed in quotes.
--
Krishnakumar S


[quoted text, click to view]
RE: inserting a single quote Billy
11/9/2006 12:46:02 AM
The data is already in the table....so 0000345 is the order numbers as they
are. Both the suggestions so far are about updating /inserting a leading
single quote into the field. I don't want to change the data in the table, I
simply want my query to return a single quote in front of the value
exported...

So I want
Select ORNO from table to return '0000345, NOT 0000345 as it does at present.

Thx

[quoted text, click to view]
RE: inserting a single quote Billy
11/9/2006 12:51:01 AM
Ok...I think I've sussed it out by writing the query thus

select top 100 char(39) + Ltrim(str(e1cano)) as newe1cano, e1mena from
EMOORDERS1

[quoted text, click to view]
AddThis Social Bookmark Button