tags:

views:

24

answers:

3

Hey all

Not sure if this is an appropriate "programming" issue but its relevant. Is there a way via SQL or excel even to add quotes to a big number of values, for example i want to add values a,b,c,d,e,f,g,j etc etc to a table is there a way i can automatically add quotes to them? as in 'a','b' etc...

i have this issue especially in my select * from table where column in ('value1','value2')...

Thanks...

A: 

Not sure if this helps or is what you were asking, but for such queries you should use parameters, i.e. something like

SELECT ... WHERE column IN (?,?)

This is not only an easy approach, but also means that if somebody puts a single-quote in the value they give you, the form of your query can't be altered - that's how SQL Injection security attacks happen.

Adrian Smith
@ adrian not what i meant... i want a way to automatically add '' to my values rather than adding the quotes and the commas by hand...each time..
andreas
neverminf..sovled using concatenate in excel thanks
andreas
A: 

If you have values in the same column of another table you coud use a select query

select '''' + cast(ValueColumn as nvarchar) + '''' as QuotedVal from MyTable

and then do your copy/paste

il_guru
I GET AN ERROR WITH that Error converting data type varchar to numeric.
andreas
Edited to works with numeric too (added the cast to nvarchar)
il_guru
A: 

Hi Andreas - I usually tackle this sort of issue using Excel - if you enter your source values in a column, you can then just use an Excel formula to concatenate the values with quotes around them (eg =CONCATENATE("'", A1, "'")), and even extend this to build the complete SQL statement.

jules