I want to store the whole values returned by a while loop. How to do this
my store procedure is like this
create proc start_proc @country varchar(20), @c_code int, @p_id int, @out_put varchar(500) output
as
if exists(select start_date from new_start where country=@country and country_code=@c_code and program_id=@p_id)
begin
set nocount on
declare @@msg1 datetime
Declare out_put cursor
local Scroll Keyset Optimistic
For
select start_date from new_start where country=@country and country_code=@c_code and program_id=@p_id
open out_put
fetch absolute 1 from out_put into @@msg1
while @@fetch_Status <> -1
begin
print @@msg1
fetch next from out_put into @@msg1
end
close out_put
Deallocate out_put
end
else
begin
set nocount on
declare @msg varchar(100)
set @msg = 'No matches are there, please try again'
print @msg
end
I want to store the values in the output parameter and later on for the programming usage.
but now I am only getting one value out. Any way out of this.
regards
shine

storing values
zhu.zheng
create proc start_proc
@country varchar(20),
@c_code int,
@p_id int
as
select start_date
from new_start
where country=@country
and country_code=@c_code
and program_id=@p_id
Please provide a sample of what you expect to be returned from SP.
P.S. When looping with cursor you should check
while @@fetch_status = 0
instead of
while @@fetch_status <> -1
Ido Tandy
Yea exactly, it's, Comma-separated list of start_date values. Therefore, I can omit recordset. These all dates are used to populate a drop down based on some country selections. So the value returned by the stored procedure is directly passed to a hidden field, with out any overheads. Does u think it is a bad thinking On the other hand, would it take any performance cost
Prof
Harreld Kuiper
shine
yogaboy
TLevin10
1. Generating comma-separated list may cause overflow errors (when the total length of the start_date values + commas will exceed specified 500 characters).
2. It is safer and faster to make a method on a client side to walk though incoming resultset using SqlDataReader and build a list/StringBuilder/whatever you need.
3. It is not a good practise to use cursors when they are not really needed. Actually in your case you can prepare a comma-separated list using unsupported query (I still suggest you to use standard select statement and process resultset on a client):
create proc start_proc
@country varchar(20),
@c_code int,
@p_id int,
@out_put varchar(500) output
as
set @out_put = ''
select @out_put = @out_put + convert(varchar(20), start_date) + ','
from new_start
where
country=@country and
country_code=@c_code and
program_id=@p_id
if len(@out_put)>0
set @out_put = left(@out_put, len(@out_put) - 1)