Click here to Skip to main content
16,012,223 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how can retrieve multiple rows of a column values from DB using a stored procedure with passing parameters.

sp_getcolumnsdata( pass an input parameter and output parameters)
based on it i want to return a multiple rows of a column

Please help me
Posted
Updated 29-Nov-11 23:06pm
v2

Based on you question my understanding is as below :
You need to return column values (comma separated or tab separated) in multiple rows. Like below example :
column value is : "AB,CD,EF,GH"
return value is :
AB
CD
EF
GH

Please see below
SQL><br
create table Testdata(SomeID int, OtherID int, Data varchar(max))
insert Testdata select 1, 9, '18,20,22'
insert Testdata select 2, 8, '17,19'
insert Testdata select 3, 7, '13,19,20'
insert Testdata select 4, 6, ''


;with tmp(SomeID, OtherID, DataItem, Data) as (
select SomeID, OtherID, LEFT(Data, CHARINDEX(',',Data+',')-1),
    STUFF(Data, 1, CHARINDEX(',',Data+','), '')
from Testdata
union all
select SomeID, OtherID, LEFT(Data, CHARINDEX(',',Data+',')-1),
    STUFF(Data, 1, CHARINDEX(',',Data+','), '')
from tmp
where Data > ''
)
select SomeID, OtherID, DataItem
from tmp
order by SomeID
 
Share this answer
 
v2
What is the problem with this? you do not need output parameters to get the output rows. You can simply select it and retrieve it in ADO.NET using DataReader. Try this up:
SQL
CREATE PROCEDURE sp_getcolumnsdata
(
@Username varchar(30),
@Password varchar(30)
)
BEGIN

SELECT firstname, lastname, age, address, city -- will return multiple rows and columns
FROM   [TableName]

END


Regards,
Eduard
 
Share this answer
 
v2
Hi,

if you need to retrieve multiple rows and column only, you do not need output parameters. only you need filter condition as input parameter.

thanks
-amit.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900