mugsey
asked on
t-sql question - multiple select statements
I have two tables
tblUser
UserID guid
isOver18 int
tblUserdetails
UserID guid
isInUSA int
isReceiveInfo int
Now I want to do a select statement that does the following
I need the result of the select statement to say somethink like the following
Number of users : 135
Number of over 18's : 87
Number of users in USA : 54
Number who want to receive info : 47
tblUser
UserID guid
isOver18 int
tblUserdetails
UserID guid
isInUSA int
isReceiveInfo int
Now I want to do a select statement that does the following
I need the result of the select statement to say somethink like the following
Number of users : 135
Number of over 18's : 87
Number of users in USA : 54
Number who want to receive info : 47
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks guys
The fields will either be zero or 1
The fields will either be zero or 1
ASKER
Also there is a similar question here
https://www.experts-exchange.com/questions/22939541/t-sql-cross-check.html
https://www.experts-exchange.com/questions/22939541/t-sql-cross-check.html
So, did the code for select statment give you the results?
ASKER
OK Guys
I get
The count aggregate operation cannot take a uniqueidentifier data type as an argument
if I try to do a count as I don't think you can do it on GUIDs?
I get
The count aggregate operation cannot take a uniqueidentifier data type as an argument
if I try to do a count as I don't think you can do it on GUIDs?
ASKER
Sorry
asvforce:
I would need the query to accept either zero 1 or NULL.
asvforce:
I would need the query to accept either zero 1 or NULL.
<The count aggregate operation cannot take a uniqueidentifier data type as an argument >
Count(*) in case of count(UserID) will do the trik.
<asvforce:
I would need the query to accept either zero 1 or NULL. >
I've already counterd that question, see differences.
Count(*) in case of count(UserID) will do the trik.
<asvforce:
I would need the query to accept either zero 1 or NULL. >
I've already counterd that question, see differences.
Differences
1) mine : ,sum(isnull(isOver18,0)) as nbrOver18
When isOver18 = 1 when true then sum works fine, must be 0 or null for false
2) astforce: count(IsOver18)
Counts the times column IsOver18 is filled up, so must be NULL when false