Recent PostsRecent Posts Popular TopicsPopular Topics
 Home Search Members Calendar Who's On

 select query Rate Topic Display Mode Topic Options
Author
 Message
 Posted Tuesday, December 03, 2013 12:13 PM
 Grasshopper Group: General Forum Members Last Login: Sunday, December 08, 2013 9:31 AM Points: 19, Visits: 35
 I know but someone posted a reply and I just replied just in case.Thanksoj
Post #1519358
 Posted Wednesday, December 04, 2013 11:13 AM
 Grasshopper Group: General Forum Members Last Login: Thursday, January 30, 2014 11:17 AM Points: 18, Visits: 177
 This should do the trick:SELECT CASE WHEN Field1 >= Field2 THEN CASE WHEN Field1 >= Field3 THEN Field1 ELSE Field3 END ELSE CASE WHEN Field2 >= Field3 THEN Field2 ELSE Field3 END END AS MaxOf3FieldsFROM MyTable
Post #1519730
 Posted Wednesday, December 04, 2013 1:24 PM
 Grasshopper Group: General Forum Members Last Login: Sunday, December 08, 2013 9:31 AM Points: 19, Visits: 35
 Or like this?--select the grandmax of the max of three columnsDECLARE @date1Max AS datetime = (SELECT MAX([orderdate]) FROM [Sales].[OrderValues]);DECLARE @date2Max AS datetime = (SELECT MAX([requireddate]) FROM [Sales].[OrderValues]);DECLARE @date3Max AS datetime = (SELECT MAX([shippeddate]) FROM [Sales].[OrderValues]);--SELECT @date1Max AS orderdate, @date2Max AS requireddate , @date3Max AS shippeddate; --TO CHECK CORRECT DATESELECT CASE WHEN @date1Max >= @date2Max AND @date1Max >= @date2Max THEN @date1Max WHEN @date2Max >= @date1Max AND @date1Max >= @date3Max THEN @date2Max ELSE @date3Max END AS GrandMax;
Post #1519773
 Posted Wednesday, December 04, 2013 3:53 PM
 Grasshopper Group: General Forum Members Last Login: Sunday, December 08, 2013 9:31 AM Points: 19, Visits: 35
 Sorry, my previous post included some mistakes.here is the corrected code:SELECT CASE WHEN @date1Max >= @date2Max AND @date1Max >= @date3Max THEN @date1Max WHEN @date2Max >= @date1Max AND @date2Max >= @date3Max THEN @date2Max ELSE @date3Max END AS GrandMax;
Post #1519821

 Permissions