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.
| Author |
Topic |
|
mapidea
Posting Yak Master
124 Posts |
Posted - 2010-02-23 : 11:47:28
|
| DECLARE @Sql_Statement VARCHAR(1000)SET @Sql_Statement = 'SELECT o.code as custnum FROM Orders oWHERE order_id IN (' + @order_ids + ')'EXEC @Sql_StatementI want the result to be with double quotes. How can I change the dynamic Sql."custnum1""custnum2""custnum3""custnum4"Sai |
|
|
Bustaz Kool
Master Smack Fu Yak Hacker
1834 Posts |
Posted - 2010-02-23 : 11:51:04
|
| SET @Sql_Statement = 'SELECT ''"'' + o.code + ''"'' as custnum FROM Orders oWHERE order_id IN ('' + @order_ids + '')'''=======================================Few things are harder to put up with than the annoyance of a good example. (Mark Twain) |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2010-02-23 : 11:55:09
|
| Why use dynamic SQL? There is risk of SQL Injection doing this - plus the user will need permissions on the underlying table - rather than just the Stored Procedure |
 |
|
|
mapidea
Posting Yak Master
124 Posts |
Posted - 2010-02-23 : 12:05:04
|
| Your code gives the messageThe multi-part identifier "o.code" could not be bound. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-23 : 12:07:14
|
quote: Originally posted by mapidea DECLARE @Sql_Statement VARCHAR(1000)SET @Sql_Statement = 'SELECT o.code as custnum FROM Orders oWHERE order_id IN (' + @order_ids + ')'EXEC @Sql_StatementI want the result to be with double quotes. How can I change the dynamic Sql."custnum1""custnum2""custnum3""custnum4"Sai
To be honest you dont need to use D-SQL here. you can just use likeSELECT o.code as custnum FROM Orders oWHERE ',' + @order_ids + ',' LIKE '%,' + CAST(order_id AS varchar(15)) + ',%' provided you pass a comma separated list as parameter value------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
mapidea
Posting Yak Master
124 Posts |
Posted - 2010-02-23 : 12:10:00
|
| Thanks a lot Visakh |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-23 : 12:21:01
|
welcome ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|