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
 Other Forums
 Other Topics
 How to do join-once-use-multiple-times joining of the tables

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2007-01-04 : 09:48:57
greg writes "i need to join 3 tables multiple times in my SQL statement which is causing a decrease a performance. would you suggest a way so that i can join only once and use multiple times that join in my query? also, i can't use PL/SQl."

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-01-04 : 10:31:11
Can you explain What you mean by i need to join 3 tables multiple times in my SQL statement. It seems you need to work on the resultset. If so

Create table #t(col1 ......)
Insert into #t
Your Join Query

Now you dont need to join 3 tables multiple times as you can make use of #t

Your subject has good naming convention

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2007-01-04 : 11:12:42
Maybe you want a cte?
http://www.simple-talk.com/sql/sql-server-2005/sql-server-2005-common-table-expressions/

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2007-01-04 : 12:09:42
Can't use.."PL/SQl."??
Is this Oracle....=> www.dbforums.com
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-04 : 13:43:59
Or make the JOIN in a VIEW and call it many times later.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-01-05 : 08:00:56
quote:
Originally posted by Peso

Or make the JOIN in a VIEW and call it many times later.


Peter Larsson
Helsingborg, Sweden

Can View support if Joins are used in Dynamic SQL?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-05 : 10:16:34
Where do Dynamic SQL come in the picture?


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-01-05 : 20:54:00
quote:
Originally posted by Peso

Where do Dynamic SQL come in the picture?


Peter Larsson
Helsingborg, Sweden

Just a thought

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -