Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
stonebreaker
Yak Posting Veteran
92 Posts |
Posted - 2009-02-04 : 14:05:13
|
| I am comparing work order hours in two different tables. Both tables have a column for number of labor hours required to complete the work order. I want to create a view that takes the greater value of the two columns and displays it.Select column_a,column_b,<the greater of>(column_c or column_d)as labor_hoursfrom table_1 join table_2on ...Is there a command or function for this? Or will I have to write a case statement?Thanks in advance, |
|
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2009-02-04 : 14:43:48
|
| no, You'll have to use case statement. |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-02-05 : 00:03:14
|
| better to use case statement as sakets saidtry ur query asselect column_1,column_b ,case when column_c > column_d then column_c else column_d end as labor_hoursfrom table_1 join table_2on.......... |
 |
|
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2009-02-05 : 06:22:12
|
| Or,You could make a function to find greater,median,avg,least etc if you need it very often. |
 |
|
|
stonebreaker
Yak Posting Veteran
92 Posts |
Posted - 2009-02-05 : 10:22:18
|
| OK, thanks for the help. Oracle has a GREATEST function, I just wondered if there was an equivalent one in SQL Server. |
 |
|
|
|
|
|