SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Lookup results in another table
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

hcmj99
Starting Member

2 Posts

Posted - 07/11/2013 :  04:55:07  Show Profile  Reply with Quote
Hi,
I have a table "Ratings" in which I store rating categories like the following:
FROM TO Rating
1 10 1
11 20 2
21 30 3

In another table "Results" I have the actual results like:
Employee ID Results Rating
120 6 ?
130 18 ?

Now I would like calculate the rating in the results table in the rating column (where "?" in the above example)

How can I do that with an SQL update command - maybe using a Case statement - but I don't know how to do that by looking up values from another table

Please advise...

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 07/11/2013 :  05:05:19  Show Profile  Reply with Quote

SELECT r.EmployeeID,r.Results,rt.Rating
FROM Results r
INNER JOIN Ratings rt
WHERE r.Results BETWEEN rt.[FROM] AND rt.[TO]


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

sigmas
Posting Yak Master

Belarus
172 Posts

Posted - 07/11/2013 :  05:11:26  Show Profile  Reply with Quote
quote:
Originally posted by visakh16


SELECT r.EmployeeID,r.Results,rt.Rating
FROM Results r
INNER JOIN Ratings rt
WHERE r.Results BETWEEN rt.[FROM] AND rt.[TO]


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs



OP needs a update statement!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 07/11/2013 :  05:22:38  Show Profile  Reply with Quote
Make it into an update

UPDATE r
SET r.Rating=rt.Rating
FROM Results r
INNER JOIN Ratings rt
WHERE r.Results BETWEEN rt.[FROM] AND rt.[TO]


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

hcmj99
Starting Member

2 Posts

Posted - 07/11/2013 :  09:39:35  Show Profile  Reply with Quote
It works.. thanks :-)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 07/11/2013 :  11:15:33  Show Profile  Reply with Quote
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000