all groups > sql server programming > august 2007 >
You're in the

sql server programming

group:

Query/Insert quoted values in the table


Query/Insert quoted values in the table research_stuff
8/24/2007 7:14:59 PM
sql server programming: Hi,

I need to insert a value into a table with single quotes around it.
For example: '2581'

The '2581' would appear in the table as shown. Is there a way of
doing this in an insert statement?


Also, when a qouted value in the table, 'PRGM', and a query is
performed against the table and the field to compare against is from
an input value, how can the query work?

For example: Select field1
from table_a
where field1 IN ('PRGM')

Note: field1 contains the value 'PRGM' and the input value is 'PRGM'

The query does not return any records when executed.




Thanks in Advance.
RE: Query/Insert quoted values in the table Alejandro Mesa
8/24/2007 7:28:02 PM
You need to double the apostrophe.

insert into dbo.t1(c1)
values(''1234'')

select *
from dbo.t1
where c1 in (''123'', ''rdf'')


AMB

[quoted text, click to view]
Re: Query/Insert quoted values in the table shiju
8/24/2007 10:04:52 PM
Use three single quotes instead of one.

create table #temp(id varchar(100))
insert into #temp
values('''1234''')

Same in the Where clause also.

Thanks,
Shiju Samuel

[quoted text, click to view]

RE: Query/Insert quoted values in the table Alejandro Mesa
8/25/2007 7:16:01 AM
Correction:

Double the apostrophes inside the string.

insert into dbo.t1(c1)
values('''1234''')

select *
from dbo.t1
where c1 in ('''123'', '''rdf''')
go

AMB

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