-
Prob: SELECT query
Hi..,
I am using SQL Server 7.0 SP2.
I've got a table x that has fields say:
id1 id2 a b c d e f
(each field name is separated by a space.
id1 + id2 is the primary key combination for this table)
If there are say 100 records in this table I can write a SELECT query like:
SELECT (a + b + c + d) AS Item
FROM x
WHERE id1 = 'my_value1' AND id2 = 'my_value2'
and I could get up to 16 records (say) using this query. The no. of records I get is variable.
My problem is to produce a single record that contains 16 Item fields. Can anyone advise me how to do this without using a cursor?
I'll be grateful for any help,
Thanks for your patience,
Cheers,
Sudhakar
-
Prob: SELECT query (reply)
You need to have fixed number of records satisfying the condition; in your example 16; so you can get 16 columns output. In this case le me know I will give you the solution. (coz' its kinda big)
But if it is not 16 always, you need to convert (a + b + c + d) into char and keep concatinating it for all records.
------------
sudhakar at 8/2/00 6:09:34 PM
Hi..,
I am using SQL Server 7.0 SP2.
I've got a table x that has fields say:
id1 id2 a b c d e f
(each field name is separated by a space.
id1 + id2 is the primary key combination for this table)
If there are say 100 records in this table I can write a SELECT query like:
SELECT (a + b + c + d) AS Item
FROM x
WHERE id1 = 'my_value1' AND id2 = 'my_value2'
and I could get up to 16 records (say) using this query. The no. of records I get is variable.
My problem is to produce a single record that contains 16 Item fields. Can anyone advise me how to do this without using a cursor?
I'll be grateful for any help,
Thanks for your patience,
Cheers,
Sudhakar
-
Prob: SELECT query (reply)
Hi..,
Thanks for the quick reply.
Ofcourse while I am concatenating a + b + c + d it is a already a char variable as all a, b, c and d fields are char data type in the table x.
Like I said I can get up to a maximum of 16 records only. At any time it can always be <= 16 records but never > 16 records.
These 16 records are to be shown as 16 fields in a single record. Fields with no values can be shown as NULL.
I'll be grateful if you have any solution.
Cheers,
Sudhakar
------------
hemanth at 8/2/00 6:53:17 PM
You need to have fixed number of records satisfying the condition; in your example 16; so you can get 16 columns output. In this case le me know I will give you the solution. (coz' its kinda big)
But if it is not 16 always, you need to convert (a + b + c + d) into char and keep concatinating it for all records.
------------
sudhakar at 8/2/00 6:09:34 PM
Hi..,
I am using SQL Server 7.0 SP2.
I've got a table x that has fields say:
id1 id2 a b c d e f
(each field name is separated by a space.
id1 + id2 is the primary key combination for this table)
If there are say 100 records in this table I can write a SELECT query like:
SELECT (a + b + c + d) AS Item
FROM x
WHERE id1 = 'my_value1' AND id2 = 'my_value2'0
and I could get up to 16 records (say) using this query. The no. of records I get is variable.
My problem is to produce a single record that contains 16 Item fields. Can anyone advise me how to do this without using a cursor?
I'll be grateful for any help,
Thanks for your patience,
Cheers,
Sudhakar
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|