samedi 19 août 2017

How do you implement if/then logic in SQL

I'm new to SQL and databases, so bear with me here.

I already know that this query isn't correct, but I think other developers here can understand what I'm trying to do. Any ideas on how to fix this query to get it to work?

         SELECT [LabTest], Count(*)
         FROM [UsersDB].[dbo].[vwUserLabTest]
         IF (LabTest='PTT') SET RangeMax=35
         IF (LabTest='CK') SET RangeMax=150
         IF (LabTest='Ca') SET RangeMax=10.1
         WHERE ResultValue>RangeMax
         GROUP By LabTest

Aucun commentaire:

Enregistrer un commentaire