lundi 10 septembre 2018

Creating conditional column in sql

I am trying to create a conditional column in TSQL like an if statement but rather than printing a string I would like it to pull through data from another column in the data set.

e.g. SELECT CASE when NameDay = 'Sunday' then [sales] 
            Else [SunAdj] END AS AdjustedDays
     FROM Table

Basically I want it to pull data from the [sales] column if the day in the NameDay column is 'Sunday' otherwise pull it from [SunAdj]. I can get it to work populating a string but not data from other columns. Is this possible? If so how? Any help would be much appreciated.

Aucun commentaire:

Enregistrer un commentaire