| Author |
Topic |
|
under2811
Constraint Violating Yak Guru
366 Posts |
Posted - 2006-08-31 : 09:44:37
|
| hello friends!!i am getting values from front end application as 1,2i am using it as '''1'',''2'''i am writing stored procedurecreate proc [dbo].[test_1] @id varchar(40)asbegindeclare @str as varchar(500)select * from table_1 where convert(varchar,uid )in (select @id)endand another is create proc [dbo].[test_1] @id varchar(40)asbegindeclare @str as varchar(500)set @str = 'select * from table_1 where convert(varchar,uid )in ('+@id+')'exec(@str)endmy table structure is name : table_1columns datatype uid intuname varchar(10)why i am getting null values for first stored procedure and if i am using second one i am getting values in query analyser but not in front end i am using ms visual studio 2005 and getting @return_value as 0 but not actual datais there any link where i find code source for getting data through stored procedure using exec(@querystr)T.I.A |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-08-31 : 09:47:41
|
| http://www.sommarskog.se/dynamic_sql.html is one source of information regarding dynamic SQL.Peter LarssonHelsingborg, Sweden |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2006-08-31 : 10:00:46
|
Try adding set nocount on in the second proc:create proc [dbo].[test_1] @id varchar(40)asbeginset nocount ondeclare @str as varchar(500)set @str = 'select * from table_1 where convert(varchar,uid )in ('+@id+')'exec(@str)set nocount offendHarsh AthalyeIndia."Nothing is Impossible" |
 |
|
|
under2811
Constraint Violating Yak Guru
366 Posts |
Posted - 2006-08-31 : 10:02:52
|
| hi Harshcan you tell me what does it make difference???????thanks |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2006-08-31 : 10:19:01
|
quote: Originally posted by under2811 hi Harshcan you tell me what does it make difference???????thanks
After each execution of the query, SQL server emits message regarding no. of rows affected. While this is fine in QA, the front-end treats each message returned as a closed recordset. So let's say, the query isselect * from authorsat the front-end side, two recordsets are returned - one containing the authors table records and another for the message - and since the message is sent after execution of query, it will be the first recordset to be received by the front-end (LIFO). SET NOCOUNT ON suppresses such messages from being sent.Here is what BOL says..."Stops the message indicating the number of rows affected by a Transact-SQL statement from being returned as part of the results."It is also better to include this statement b'coz it avoids unnecessary confirmation messages, thus reducing network traffic and boosting overall performance.Harsh AthalyeIndia."Nothing is Impossible" |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-08-31 : 11:59:04
|
| Without Dynamic SQL, tryselect * from table_1 where '%,'+@id+',%' like '%,'+cast(id as varchar(10))+',%'MadhivananFailing to plan is Planning to fail |
 |
|
|
under2811
Constraint Violating Yak Guru
366 Posts |
Posted - 2006-09-01 : 00:56:54
|
| hi Madhivanan!!!!got it!!!!!thanks |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-09-01 : 01:55:31
|
| Also send the parameters as "'1', '2'". Only double qoutes first and last.Peter LarssonHelsingborg, Sweden |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-09-02 : 12:02:56
|
| If id is of integer datatype, then use '1,2'MadhivananFailing to plan is Planning to fail |
 |
|
|
|