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
 Populating a table
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sadbjp
INNER JOIN

41 Posts

Posted - 05/11/2007 :  13:34:32  Show Profile  Reply with Quote
Hi, I have two tables:

1. RubricReportDetail with columns LocalPerf, Age
2. SppIndicator with columns Pct, Age

How can I populate the values of LocalPerf with Pct by matching

RubricReportDetail.Age = SppIndicator.Age ??

Please help me. Thanks in advance.

tkizer
Almighty SQL Goddess

USA
36601 Posts

Posted - 05/11/2007 :  13:40:40  Show Profile  Visit tkizer's Homepage  Reply with Quote
UPDATE r
SET LocalPerf = s.Pct
FROM RubricReportDetail r
INNER JOIN SppIndicator s
ON r.Age = s.Age

Tara Kizer
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

sadbjp
INNER JOIN

41 Posts

Posted - 05/11/2007 :  13:42:20  Show Profile  Reply with Quote
Hi,
Thanks for the response. What if I don't wanto join INNER join. Is there any other way (simplest one ) to do this?

Let me know. Thanks very much.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 05/11/2007 :  13:44:10  Show Profile  Reply with Quote
Huh?

What's wrong with that?

Is this a homework assignment?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

sadbjp
INNER JOIN

41 Posts

Posted - 05/11/2007 :  13:45:46  Show Profile  Reply with Quote
It is certainly not a homework assignment but I hate using INNER joins, I want to use another method (just want to avoid joins). Can I use WHERE clause in this?
Go to Top of Page

spirit1
Cybernetic Yak Master

Slovenia
11750 Posts

Posted - 05/11/2007 :  13:48:29  Show Profile  Visit spirit1's Homepage  Reply with Quote
you hate using inner joins???

maybe you should change the field you work in?

joins are a basis of set operations and thus Databases.

EDIT: fixed some typos

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp

Edited by - spirit1 on 05/11/2007 13:49:45
Go to Top of Page

tkizer
Almighty SQL Goddess

USA
36601 Posts

Posted - 05/11/2007 :  13:48:31  Show Profile  Visit tkizer's Homepage  Reply with Quote
I will not provide bad answers. Learn to write good code and start using joins.

Tara Kizer
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

sadbjp
INNER JOIN

41 Posts

Posted - 05/11/2007 :  14:05:14  Show Profile  Reply with Quote
Thanks for the help but didn't asked for your opinions about my likes and dislikes.
Go to Top of Page

jsmith8858
Dr. Cross Join

USA
7423 Posts

Posted - 05/11/2007 :  14:08:50  Show Profile  Visit jsmith8858's Homepage  Reply with Quote
sadbjp -- it is not an opinion to state that if you don't "like joins", you shouldn't be working with a relational database. that's a fact.

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

tkizer
Almighty SQL Goddess

USA
36601 Posts

Posted - 05/11/2007 :  14:08:59  Show Profile  Visit tkizer's Homepage  Reply with Quote
It's not about likes and dislikes; it's about writing good, efficient code.

The most efficient way to do this is with a join.

Tara Kizer
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

sadbjp
INNER JOIN

41 Posts

Posted - 05/11/2007 :  14:13:33  Show Profile  Reply with Quote
Alright guys..lets end this here. Thanks once again for your help and guidance.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 05/11/2007 :  14:30:38  Show Profile  Reply with Quote
OK, Here's the answer you want

You need to write a cursor based on the first table
Then do a siglenton update based on the key

That's the (wrong) answer you are looking for



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30113 Posts

Posted - 05/14/2007 :  08:45:57  Show Profile  Visit SwePeso's Homepage  Reply with Quote
UPDATE	d
SET	d.LocalPerf = (SELECT i.PCT FROM SppIndicator AS i WHERE i.Age = d.Age)
FROM	RubricReportDetail AS d


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

Vijaykumar_Patil
Posting Yak Master

India
121 Posts

Posted - 05/14/2007 :  09:35:13  Show Profile  Visit Vijaykumar_Patil's Homepage  Click to see Vijaykumar_Patil's MSN Messenger address  Reply with Quote
Isn't this slower than Tara's method. Which I normally use.


Necessity is the mother of all inventions!
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30113 Posts

Posted - 05/14/2007 :  10:23:25  Show Profile  Visit SwePeso's Homepage  Reply with Quote
It can be. It depends on how smart SQL Server is.
But it meets OP original condition, NO JOIN ALLOWED.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22744 Posts

Posted - 05/14/2007 :  10:55:59  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
quote:
Originally posted by sadbjp

It is certainly not a homework assignment but I hate using INNER joins, I want to use another method (just want to avoid joins). Can I use WHERE clause in this?


Which of the following is correct?
1 You dont know how to use Join
2 You are new to sql and want to use front end's row by row operation (as suggested cursor)
3 You dont know how to justify the statement "I hate using INNER joins"

Madhivanan

Failing to plan is Planning to fail
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.09 seconds. Powered By: Snitz Forums 2000