vendredi 22 avril 2016

Error in CASE keyword while executing the SQL query in SQL Server

I am executing this query in SQL server but do not know, why it is giving error in "CASE" and "IN" keywords. I am really stuck here. Please help me.I will be very thankful to you.Here is my query.

  SELECT [id]
  ,[name]
  SUM(CASE WHEN (SELECT [code] 
                   FROM [Test].[dbo].[testcode] as ts 
                   WHERE ts.id = t.id) IN (1,2,4) 
            then 100 
            else 10 
           end) as "total" 
  FROM [Test].[dbo].[testcode] as t 
  GROUP BY id, name

Aucun commentaire:

Enregistrer un commentaire