Possible Duplicate:
Count the Null columns in a row in SQL
I've had a dig around for answers to this, but can't find either a working or suitable answer and I'm a novice with SQL.
I've got a table containing teams for an event, and amongst other columns I have team_member_1
, team_member_2
, team_member_3
, team_member_4
, team_member_5
. Each one stores the name of that team memember, each team has a different amount of members (between 3 and 5).
I'm trying count the number of people in a team by counting how many columns/ fields within that row/team are NOT NULL
.
If my head if would go something like:
Select Count NOT NULL team_member_1, team_member_2, team_member_3,
team_member_4, team_member_5
from Teams
where team_id = 5
Of course this doesn't work. I then want to times this figure by £20 (as the event cost is £20 per head), to give me the amount each team owes, and that will be echo'd out on the website. Hope all makes sense.