samedi 24 octobre 2015

How do I use this condition inside CASE WHEN?

I want if Status column = 1

Check If there are rows in another table return 'Check' and If no rows return 'In DB'

SELECT ID, UserName,
CASE [Status]
    WHEN 1 THEN
        if ((Select Count(*) From Logs_TB Where Logs_TB.UserName = Users_TB.UserName) > 0)
            'Check'
        Else
            'In DB'
    WHEN 2 THEN 'Revision'
    WHEN 3 THEN 'Sent'
END AS StatusName
FROM Users_TB CROSS JOIN Logs_TB

Aucun commentaire:

Enregistrer un commentaire