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
 Populating a table

Author  Topic 

sadbjp
INNER JOIN

41 Posts

Posted - 2007-05-11 : 13:34:32
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

38200 Posts

Posted - 2007-05-11 : 13:40:40
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 - 2007-05-11 : 13:42:20
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 - 2007-05-11 : 13:44:10
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 - 2007-05-11 : 13:45:46
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

11752 Posts

Posted - 2007-05-11 : 13:48:29
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
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-05-11 : 13:48:31
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 - 2007-05-11 : 14:05:14
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

7423 Posts

Posted - 2007-05-11 : 14:08:50
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

38200 Posts

Posted - 2007-05-11 : 14:08:59
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 - 2007-05-11 : 14:13:33
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 - 2007-05-11 : 14:30:38
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

30421 Posts

Posted - 2007-05-14 : 08:45:57
[code]UPDATE d
SET d.LocalPerf = (SELECT i.PCT FROM SppIndicator AS i WHERE i.Age = d.Age)
FROM RubricReportDetail AS d[/code]

Peter Larsson
Helsingborg, Sweden
Go to Top of Page

Vijaykumar_Patil
Posting Yak Master

121 Posts

Posted - 2007-05-14 : 09:35:13
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

30421 Posts

Posted - 2007-05-14 : 10:23:25
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

22864 Posts

Posted - 2007-05-14 : 10:55:59
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
   

- Advertisement -