Groups | Blog | Home
all groups > sql server mseq > january 2006 >

sql server mseq : SQL Query


Mukesh Garg
1/9/2006 12:40:02 AM
Hi all, i am not able to make up a query according to my need. can anyone
help. Following is my simple query.

select udf_name [Severity],st_name [Status], count(2) [count]
from bugs, statuses, user_defined_attribute
where udf_id = bg_user_defined_attribute
and bg_status = st_id
group by udf_name,st_name
order by udf_name

i want it to be shown in following manner: distinct "udf_name" is shown as
rows and distinct "st_name" as columns and corrospond to them come the count
for respective

say
st_name[1] st_name[2]
udf_name 1 2

and so on.

Please help
Regards
Mukesh Garg
1/10/2006 8:07:01 PM
Thanks Hugo Kornelis

it works......

thanks a lot

[quoted text, click to view]
Hugo Kornelis
1/10/2006 11:00:18 PM
[quoted text, click to view]

Hi Mukesh,

It's easier to help you if you post the structure of your tables (as
CREATE TABLE statements), some sample data (as INSERT statements) and
expected results.

Based on what you write and a fair number of assumptions, try something
like this:

SELECT udf_name,
SUM(CASE WHEN st_name = '1' THEN 1 ELSE 0 END) AS "st_name[1]",
SUM(CASE WHEN st_name = '2' THEN 1 ELSE 0 END) AS "st_name[2]"
FROM bugs, statuses, user_defined_attribute
WHERE udf_id = bg_user_defined_attribute
AND bg_status = st_id
GROUP BY udf_name

If this doesn't do what you want, then check out www.aspfaq.com/5006.

--
AddThis Social Bookmark Button