Sunday 15 March 2015

sql server - SQL MIN and MAX when only one row -


I have 2 lines in my query that select the minimum and maximum values ​​from the table. There are likely to be the maximum number of rows returned only twice, but if only 1 is returned, then I do not want some other return.

IE:

  Max (in case BD .. DIETEX = 'Tuesday' and B.D.) Booking Time = 3 and Convert (Time (0) , BD.starttime) & lt; Convert (Time (0), '12: 00: 00 ') and Bd.NoOfHOurs & lt; 5.5 and s.PrimarySchool = 1 THEN BD.ID ELSE NAL END) "Tuesday HourlyAM", Min (case when BD .. Dietest = 'Tuesday' and BD. Booking Period = 3 and Convert (Time) (0), BD. Starttime) Convert (Time (0), '12: 00: 00 ' ) And B.D.offhors & lt; 5.5 and s.PrimarySchool = 1 THEN BD.ID ELSE Null & ") Glwar HourlyAM2 ",   

theres so that 1 row back, should clear Tuesday HourlyAM2.

Any thoughts?

Thanks

Try wrapping it in the case statement :

  (when the count (*)> 1 then (case when B.D.I..Teth = 'Tuesday' and BD bookingDetail = 3 and convert (time (0) , BD.starttime) and LT; Convert (Time (0), '12: 00: 00 ') and BD .offhors & lt; 5.5 and s.PrimarySchool = 1 THEN BD.ID ELSE Null & End) Tuesday HourlyAM2    

No comments:

Post a Comment