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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 To put earning into categories

Author  Topic 

gamaz2
Starting Member

31 Posts

Posted - 2012-09-10 : 17:47:49
Hi I have a column in a table that calculates earning (part time). In the test system the earning is: the first row is 4000, the second row is 10000 the third row is 15000 and fourth row is 25000. There is a separate category table where the first row 0-5999 the second row is 6000-11999 the third row is 12000-23999 and the fourth row is 24000-above. Now how does one do a query to have the earnings and the corresponding categories the earning fall which means the two columns are earning and category. I appreciate any help. Thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-09-10 : 17:56:46
[code]
SELECT t.earning,c.categorydescription
FROM Table t
INNER JOIN Category c
ON t.earning BETWEEN c.categorystart and c.categoryend
[/code]

i've assumed column names so make sure you use correct column names instead
i've assumed you've category values stored in two fields (start and end)

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -