Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Counting Different Values in the same field
Message
 
 
To
06/08/2003 15:37:42
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Miscellaneous
Thread ID:
00817447
Message ID:
00817449
Views:
15
This message has been marked as the solution to the initial question of the thread.
Terry,

Try
SELECT DataOwner ;
		SUM(CASE WHEN intvalue=1 THEN 1 ELSE 0 END) AS cnt1 
		SUM(CASE WHEN intvalue=2 THEN 1 ELSE 0 END) AS cnt2
		...	
		SUM(CASE WHEN intvalue=11 THEN 1 ELSE 0 END) AS cnt11
	FROM mytable
	GROUP BY DataOwner	 
>What is the best way to count the total number of occurences of values that reside in the same column. I want to get these counts as 1 row grouped by owner.
>Final requirement - accomplish this in a stored procedure.
>
>I could run 9 COUNTS(*)s to get the data but that seems wrong.
>
>Table Stru
>ID INT 4
>INTVALUE INT 4
>DATAOWNER VARCHAR(3)
>
>
>Int values range of allowable values is 1,2,3,4...,11
>
>I want to create a return rowset with the number of
>1's in Col 1
>2's in Col 2
>3's in Col 3
>etcs
>Example
>Number of 1's   Number of 2's   Number of 3's
>21              42              84
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform