Help with TSQL query
I'm using SQL-Server 2005 Standard.
I have Users table with following columns:
userID(int),
userImage(varchar),
userText(varchar),
userLastVisit(smalldatetime),
isActivated (bit),
userHobby1 (bit),
.....
userHobby10 (bit)
userCharacteristic1 (bit),
.....
userCharacteristic10 (bit)
I did 6 queries to select
- users that haven't been on site for two weeks
- users that doesn't have picture
- users that doesn't have text
- users that doesn't have a single hobby
- users that doesn't have a s开发者_JAVA技巧ingle characteristic
- users that did not activate their account
Now what i need to get is list of users with actions that need to be told about.
For example userID 2004 doesn't have an image and doesn't have a single hobby. Each single user should appear only once in the list with all it's actions need to be done.
Thanks in advance.
Try string concatenation and CASE WHEN:
SELECT UserID,
CASE WHEN UserImage IS NULL THEN 'no image.' ELSE '' END +
CASE WHEN UserText IS NULL THEN 'no text.' ELSE '' END +
... -- more CASE WHEN conditions
AS Info
WHERE (UserImage IS NULL)
OR (UserText IS NULL)
... -- OR same conditions as in CASE WHEN clauses
精彩评论