Microsoft
Software
Hardware
Network
Question : Combine data from several rows into a single result
Hi Experts,
I have something that has been puzzling me for days.
I've got a SPROC that queries one or two tables and returns rows appropriately and as expected.
The problem is that I now need to query a single column in a different table which may have up to four rows. I want to concatenate the values from the four rows and return them as one column in the existing SPROC.
I thought of declaring a local variable and updating it with a correlated sub-query and returning that as a single value in the select statement in my main sproc. However SqlServer says that I can't mix the update with the select.
What's the best strategy for this kind of thing? Any help would be very much appreciated.
Answer : Combine data from several rows into a single result
Try this...
SELECT CITY, COUNT(ID) AS TOTALREGISTERED, SUM(CASE WHEN ATTENDED='Y' THEN 1 ELSE 0 END) as TOTALATTENDED FROM REGISTRATIONS GROUP BY CITY ORDER BY CITY
Random Solutions
C# 4.0 convert from 12h format to 24h format.
MS Access not connecting to Oracle11g using ODBC
imac osx 10.5 - Does not boot; cannot find harddrive. Getting a folder icon wid a question mark flashin at startup
GridView control scroll bars are not visible on page reload
How can I convert a custom control that calls User32 and Shell32 to work on Mono?
how can i find all ILO boards on a network
Excel Date Time format conversion yyyy-mmm-dd hh:mm:ss to mm/dd/yyyy hh:mm:ss
VB .NET 2005 Combine Two Tables on Primary Key and Display in DataGridView
V2P (Windows 2008)
Setting up my first database driven web site