• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 970
  • Last Modified:

query to find the lower values of two columns for sql server

I have the following table columns .  
emp_no, bonus1, bonus2

I like a simple sql to find the lower value of bonus1 and bonus2, so the out_put is:
emp_no, lower_of_bonus1_bonus2
0
ewang1205
Asked:
ewang1205
2 Solutions
 
Daniel ReynoldsSoftware Applications Developer / IntegratorCommented:
Something like the following

Select emp_no, Case When bonus1 < bonus2 Then bonus1 Else bonus2 end
from mytable
0
 
brad2575Commented:
try this:
select emp_no, case when bonus1 < bonus2
            then bonus1
            else bonus2 end as lower_of_bonus1_bonus2
  from TableName

Open in new window

0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now