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 |
|
Shilpa22
Starting Member
37 Posts |
Posted - 2009-05-18 : 03:26:55
|
| Hi All,I am new to Sql Sever. Pls help me out.I am trying to create a spCREATE PROCEDURE proc_ins_TestDetails ( @Title nvarchar(100), @Base_Filter_Id char(3) ) asset @Base_Filter_Id = 'select distinct(Base_Filter_Id) from filtersmaster'.I want 'select distinct(Base_Filter_Id) from filtersmaster' result to be set in @Base_Filter_Id.How to do it?Thanks in AdvanceShilpa |
|
|
ergen
Starting Member
5 Posts |
Posted - 2009-05-18 : 03:50:32
|
| This one will work, but I'm not sure if you are aware of the fact that this query in procedure can return more that 1 record. In such situation you will get an error... look at http://www.jacek-szarapa.com/index.php?p=sql&d=3 that will help with the problem when more than one record is returned.CREATE PROCEDURE [dbo].proc_ins_TestDetails(@Title nvarchar(100),@Base_Filter_Id char(3) output)asbegin select @Base_Filter_Id = distinct(Base_Filter_Id) from filtersmasterendgodeclare @Base_Filter_Id1 char(3);exec proc_ins_TestDetails @Base_Filter_Id=@Base_Filter_Id1, @Title=''select @Base_Filter_Id1----------------Jacek Szarapahttp://www.jacek-szarapa.com |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-05-18 : 04:43:12
|
if you have multiple value for base_filter_id, maybe you can form a CSV (comma separated value)declare @base_filter_id varchar(max)select @base_filter_id = isnull(@base_filter_id + ',', '') + base_filter_id from filtersmaster group by base_filter_id and then pass the CSV value into your stored procedure. Your stored procedure will need to modify to handle the CSV input value.Make use of CSVTable or fnParseList found herehttp://www.sqlteam.com/forums/topic.asp?TOPIC_ID=25830&SearchTerms=CSVTablehttp://www.sqlteam.com/forums/topic.asp?TOPIC_ID=76033 KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-05-18 : 04:52:01
|
quote: Originally posted by ergen This one will work, but I'm not sure if you are aware of the fact that this query in procedure can return more that 1 record. In such situation you will get an error... look at http://www.jacek-szarapa.com/index.php?p=sql&d=3 that will help with the problem when more than one record is returned.CREATE PROCEDURE [dbo].proc_ins_TestDetails(@Title nvarchar(100),@Base_Filter_Id char(3) output)asbegin select @Base_Filter_Id = distinct(Base_Filter_Id) from filtersmasterendgodeclare @Base_Filter_Id1 char(3);exec proc_ins_TestDetails @Title='',@base_filter_id1 outputselect @Base_Filter_Id1----------------Jacek Szarapahttp://www.jacek-szarapa.com
|
 |
|
|
Shilpa22
Starting Member
37 Posts |
Posted - 2009-05-18 : 05:01:04
|
| Thanks Folks,It resolved my problem..Thanks a lot for u r helpThanks in AdvanceShilpa |
 |
|
|
ergen
Starting Member
5 Posts |
Posted - 2009-05-18 : 05:27:48
|
quote: Originally posted by khtan if you have multiple value for base_filter_id, maybe you can form a CSV (comma separated value)declare @base_filter_id varchar(max)select @base_filter_id = isnull(@base_filter_id + ',', '') + base_filter_id from filtersmaster group by base_filter_id and then pass the CSV value into your stored procedure. Your stored procedure will need to modify to handle the CSV input value.Make use of CSVTable or fnParseList found herehttp://www.sqlteam.com/forums/topic.asp?TOPIC_ID=25830&SearchTerms=CSVTablehttp://www.sqlteam.com/forums/topic.asp?TOPIC_ID=76033 KH[spoiler]Time is always against us[/spoiler]
another approach to CSVTable is here http://www.jacek-szarapa.com/index.php?p=sql&d=2. there is no need to use loop to solve the problem.----------------Jacek Szarapahttp://www.jacek-szarapa.com |
 |
|
|
|
|
|
|
|