Hi,
I am a new comer to sql server. I could write simple procedures. I have
a table like this
Field1 Field2 Field3
1 one name-1
2 two name-2
1 one name-3
I have to write a procedure to return the values of the records for all the
records with Field1 equal to 1 in the format:
1,one,name-1,name-3
As in the above case two records match so I return total four values with
two name values. If three records would have matched I would have returned
three name values in the response, so in that case the total values to be
returned would have been 5.
I just wonder how I would write this procedure some thing like
create procedure dbo.getvalues input int, output1 int OUTPUT, output2
char(10) OUTPUT....
as
select Field1,Field2,Field3 ...
How can I declare a variable limit to output fileld ? I mean the output from
this procedure could be 4 fields 5 fields or 6 fileds or more ....
Thanks for any help in this matter.
JSJS
I'd strongly recommend you doing such reports on the client side. This
solution is not reliable.
CREATE TABLE #Test
(
col1 INT NOT NULL,
col2 CHAR(1) NOT NULL,
col3 CHAR(2) NOT NULL
)
INSERT INTO #Test VALUES (1,'A','BB')
INSERT INTO #Test VALUES (2,'G','DD')
INSERT INTO #Test VALUES (1,'A','CC')
DECLARE @.st VARCHAR(50)
SET @.st=''
SELECT @.st=@.st+ col2+','+col3 FROM #Test WHERE col1=1
SELECT @.st
"JS" <JS@.discussions.microsoft.com> wrote in message
news:A122B6DE-DD0D-49D6-99A1-A5D7F63933F0@.microsoft.com...
> Hi,
> I am a new comer to sql server. I could write simple procedures. I
> have
> a table like this
> Field1 Field2 Field3
> 1 one name-1
> 2 two name-2
> 1 one name-3
>
> I have to write a procedure to return the values of the records for all
> the
> records with Field1 equal to 1 in the format:
> 1,one,name-1,name-3
>
> As in the above case two records match so I return total four values with
> two name values. If three records would have matched I would have returned
> three name values in the response, so in that case the total values to be
> returned would have been 5.
> I just wonder how I would write this procedure some thing like
> create procedure dbo.getvalues input int, output1 int OUTPUT, output2
> char(10) OUTPUT....
> as
> select Field1,Field2,Field3 ...
> How can I declare a variable limit to output fileld ? I mean the output
> from
> this procedure could be 4 fields 5 fields or 6 fileds or more ....
> Thanks for any help in this matter.
> JS
>|||Maybe this might help:
http://milambda.blogspot.com/2005/0...s-as-array.html
And I strongly agree with Uri - this belongs on the presentation layer, not
the data layer.
MLsql
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment