There are 2 tablesdbo.Application :
| id | RealResID | +----+-----------+ |337 | 4 | dbo.Resolutions | id | AppID | ResID | date | CreatedAt | +------+-------+-------+------------+------------+ | 114 | 337 | 2 | null | 2016-12-12 | | 257 | 337 | 3 | 2016-10-27 | 2016-12-12 | | 300 | 337 | 4 | 2016-11-01 | 2016-12-12 | You need to select a date if ResID = 4 then select a date not according to your own, but on 2016-10-27 ( ResID = 3 )
And in other cases, choose a date according to your own (ifResID = 2 then null , ResID = 3 then 2016-10-27 )
My request:
select id, case when ResID = 3 then date case when ResID = 4 then (case when ResID = 3 then date) else createdAt from dbo.Application a left join Resolutions r on a.id = r.appID and r.ResID = a.RealResID
case when ... then [else] end! Here is theselect id, case when ResID = 4 then cast( '2016-10-27' as date ) else date end from dbo.Applicationand the feature, the type in case when should be the same . Well, go to msdn on the website of the Borg, everything is beautiful with examples. - nick_n_aselect id, case when ResID <> 4 then date else '2016-10-27' end from dbo.Applicationor a parameter?or@dateinstead of a constant. - nick_n_a