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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Between condition

Author  Topic 

pecusio
Starting Member

5 Posts

Posted - 2010-02-01 : 05:34:56
I have two table one have a range that identify a sector, something like

Sector Initial Final
Finance 1 1200
Health 1340 2144


In another table I have a code that identify each company to a sector, I would like to have a condition on my query that when the code of the company is between the initial and final it brings me the sector but when the code does not match any sector from the first table it bring me "other"

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-01 : 05:40:02
[code]SELECT t.*,COALESCE(s.Sector,'Other')
FROM YourTable t
LEFT JOIN SectorTable s
ON t.code BETWEEN s.Initial AND s.Final
[/code]
Go to Top of Page

pecusio
Starting Member

5 Posts

Posted - 2010-02-01 : 06:02:52
Thanks for the fast response
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-01 : 06:06:20
welcome
Go to Top of Page
   

- Advertisement -