Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need help with 'COUNT' which seems to be counting a blank? 1

Status
Not open for further replies.

DougP

MIS
Dec 13, 1999
5,985
US
I am trying to count the number of 'G's in 3 columns for 2 rows.
The top script is one of the 3 which is causing a problem. Count(RGB_STSOnly) returns a 1. In double checking I ran the bottom script and there is nothing showing but an empty box in the "Results to Grid".
The RGB_STSOnly column does have a 'B' in row 2, but I need to count the number of 'G''s in the column for rows 1 and 2 and get a total.
Obviously counting a 1 for that is invalid if I am looking for 'G's. Can someone help me figure out what to look for to make it 0 if there are no G's ?
I have another one which returns a Null since there are no G's or B' and its count is zero so not sure what's going on with this script?
See attachment

TIA

Code:
Select   Count(RGB_STSOnly) as  Count_RGB_STSOnly
		from histdata Where 
		RecordID Between 1  
		AND 2  
		AND RGB_TckrPercent = 'G'
----
Select   RGB_STSOnly
	        from histdata Where 
		RecordID Between 1  
		AND 2  
		AND RGB_TckrPercent = 'G'


DougP
 
 http://files.engineering.com/getfile.aspx?folder=3eb7051d-969e-46ca-9bc9-b6242991da8c&file=SQL_count.JPG
Count(column) will count all rows where the column isn't NULL. ANY other values are counted, also blank ones. By all means no difference is made per character.
Counting only Gs: SUM(CASE WHEN RGB_STSOnly='G' THEN 1 ELSE 0) as GCount.

Bye, Olaf.
 
Works great
I had to add the "END" on the end but thankyou
Code:
SUM(CASE WHEN RGB_STSOnly='G' THEN 1 ELSE 0 [COLOR=red][b]END[/b][/color])

DougP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top