Skip to content Skip to sidebar Skip to footer

Conditional Where Statement In T-sql

I've got a table that returns the history of a value, as well as the current one, each with a date. The oldest date is the main record. If the value is changed, a new record is cr

Solution 1:

Try this:

SELECT EmergencyAttendanceId


    casewhencount(EmergencyAttendanceId) >1thenMIN
          (
          casewhen TriageDateTime isnullthen SourceCreateDateTime end 
          ) 
    elsemin(SourceCreateDateTime)
    endas max_date


    FROM FactEmergencyAttendanceTriageDetail 
    GROUPBY EmergencyAttendanceId 

Solution 2:

Use CASE in place of your pseudo-code:

WHERE TriageEndDateTime =CASEWHEN EmergencyAttendanceId >1THENNULLELSENOTNULLEND

Post a Comment for "Conditional Where Statement In T-sql"