• ckmoied (10/8/2007)


    Thank you ALZDBA

    Actually your solution is similar to

    select Facility1 as [Facility 1]

    ,(select count(*) FROM MyTable WHERE Cond1) as [First Condition]

    ,(select count(*) FROM MyTable WHERE Cond2) as [Second Condition]

    ,(select count(*) FROM MyTable WHERE Cond3) as [Third Condition]

    Now what about the 2nd row, how do I use carriage return and start the 2nd line for Facility2. I don't want to use a separate select statement for the 2nd Facility, so that my result appear like a table.

    Remember, SQL is meant for returning a resultset and the UI layer is meant for formatting and presentation. I am sure there is at least 1 member of SSC that could provide with a T-SQL solution for your question, but SQL Is not the best tool for doing presentation and formatting. Pretty much any solution you will get with SQL Server will return a result like:

    Facility Condition1 Condition2 Condition3

    ------- ---------- ---------- ----------

    Facility1 10 12 14

    Facility2 7 18 22

    You would then use your UI to format as you like. IF you have SQL 2000 or later you can use SSRS which easily allows what you want, as would Crystal Reports, or some other report writer.