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

 Minimum Value 3 Fields > 0 Rate Topic Display Mode Topic Options
Author
 Message
 Posted Wednesday, September 12, 2012 9:24 PM
 Hall of Fame Group: General Forum Members Last Login: Wednesday, February 24, 2016 6:28 AM Points: 3,977, Visits: 6,431
 Ah yes, NULLIF... Forgot about that one.That will work but we still need to hear from the OP their preferred return result for that case so it can be plugged into your version of my query. My mantra: No loops! No CURSORs! No RBAR! Hoo-uh!My thought question: Have you ever been told that your query runs too fast?My advice:INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.Need to UNPIVOT? Why not CROSS APPLY VALUES instead?Since random numbers are too important to be left to chance, let's generate some!Learn to understand recursive CTEs by example.Splitting strings based on patterns can be fast!My temporal SQL musings: Calendar Tables, an Easter SQL, Time Slots and Self-maintaining, Contiguous Effective Dates in Temporal Tables
Post #1358314
 Posted Wednesday, September 12, 2012 9:53 PM
 SSC Veteran Group: General Forum Members Last Login: 2 days ago @ 7:21 PM Points: 240, Visits: 357
 If all three are zero, desired result would be zero.
Post #1358321
 Posted Wednesday, September 12, 2012 9:54 PM
 Hall of Fame Group: General Forum Members Last Login: Wednesday, February 24, 2016 6:28 AM Points: 3,977, Visits: 6,431
 texpic (9/12/2012)If all three are zero, desired result would be zero.What if all 3 are negative? Still zero? My mantra: No loops! No CURSORs! No RBAR! Hoo-uh!My thought question: Have you ever been told that your query runs too fast?My advice:INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.Need to UNPIVOT? Why not CROSS APPLY VALUES instead?Since random numbers are too important to be left to chance, let's generate some!Learn to understand recursive CTEs by example.Splitting strings based on patterns can be fast!My temporal SQL musings: Calendar Tables, an Easter SQL, Time Slots and Self-maintaining, Contiguous Effective Dates in Temporal Tables
Post #1358323
 Posted Thursday, September 13, 2012 2:31 AM
 SSCrazy Eights Group: General Forum Members Last Login: Thursday, December 1, 2016 10:11 AM Points: 8,587, Visits: 18,753
 `SELECT Id, A, B, C, MinVal FROM #MinAmtCROSS APPLY ( SELECT MIN(a) FROM (VALUES (A),(B),(C) ) v (a) WHERE a > 0) x (MinVal) ` “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail ShawFor fast, accurate and documented assistance in answering your questions, please read this article.Understanding and using APPLY, (I) and (II) Paul White Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff ModenExploring Recursive CTEs by Example Dwain Camps
Post #1358396
 Posted Thursday, September 13, 2012 4:55 AM
 Hall of Fame Group: General Forum Members Last Login: Wednesday, February 24, 2016 6:28 AM Points: 3,977, Visits: 6,431
 ChrisM@Work (9/13/2012)`SELECT Id, A, B, C, MinVal FROM #MinAmtCROSS APPLY ( SELECT MIN(a) FROM (VALUES (A),(B),(C) ) v (a) WHERE a > 0) x (MinVal) `And the referee throws down a red penalty flag!This is the SQL 2005 forum! My mantra: No loops! No CURSORs! No RBAR! Hoo-uh!My thought question: Have you ever been told that your query runs too fast?My advice:INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.Need to UNPIVOT? Why not CROSS APPLY VALUES instead?Since random numbers are too important to be left to chance, let's generate some!Learn to understand recursive CTEs by example.Splitting strings based on patterns can be fast!My temporal SQL musings: Calendar Tables, an Easter SQL, Time Slots and Self-maintaining, Contiguous Effective Dates in Temporal Tables
Post #1358469
 Posted Thursday, September 13, 2012 5:11 AM
 SSCrazy Eights Group: General Forum Members Last Login: Thursday, December 1, 2016 10:11 AM Points: 8,587, Visits: 18,753
 dwain.c (9/13/2012)ChrisM@Work (9/13/2012)`SELECT Id, A, B, C, MinVal FROM #MinAmtCROSS APPLY ( SELECT MIN(a) FROM (VALUES (A),(B),(C) ) v (a) WHERE a > 0) x (MinVal) `And the referee throws down a red penalty flag!This is the SQL 2005 forum!Challenged! texpic always posts in the 2K8 forum! “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail ShawFor fast, accurate and documented assistance in answering your questions, please read this article.Understanding and using APPLY, (I) and (II) Paul White Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff ModenExploring Recursive CTEs by Example Dwain Camps
Post #1358476
 Posted Thursday, September 13, 2012 6:33 AM
 SSC Journeyman Group: General Forum Members Last Login: Tuesday, January 5, 2016 5:45 AM Points: 78, Visits: 317
 Try Thisselect Id,MIN(a) from (select a.id, a.a from #MinAmt a ,#MinAmt union select a.id, a.b from #MinAmt a ,#MinAmtunion select a.id, a.c from #MinAmt a ,#MinAmt) a where a>0 group by Id
Post #1358512

 Permissions