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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Code to chage user's input:123, 234 to '123','234'

Author  Topic 

Sun Foster
Aged Yak Warrior

515 Posts

Posted - 2008-05-03 : 07:26:22
I need to convert user's input to SQL statement.
How to code to chage user's input:123, 234 to '123','234'

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-03 : 07:39:29
'''' + REPLACE(YourSQLStringField,',',''',''') + ''''
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-05-03 : 08:55:04
Also consider
http://www.sommarskog.se/arrays-in-sql.html

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2008-05-05 : 14:33:33
Although the same as Visakh's sample, you might want to consider using CHAR(39) in palce of a sinlge quote when building dynamic strings:
CHAR(39) + REPLACE(YourSQLStringField, ',', CHAR(39) + ',' + CHAR(39)) + CHAR(39)
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2008-05-05 : 15:40:08
If this is really a user's input, you should parse and fix it up at the client tool that is accepting the input. (i.e., the web page or the application that is presenting the UI)

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page
   

- Advertisement -