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 2000 Forums
 Transact-SQL (2000)
 Stored procedure

Author  Topic 

reflex2dotnet
Yak Posting Veteran

99 Posts

Posted - 2007-05-18 : 13:59:20
Hi all,

Can anyone please help me to write a SP, which includes the following in resultset

The select statemnet will contain many inner joins, and i am not at all familiar with them

Dbo.Call
CalID

dbo.Order
Orderid
calid
orderdate

dbo.ship
packid
orderid
shipdate
weight
cost

The result set should have callid, orderid, packid,weight,cost,orderdate, shipdate

Depending on this select statement, i have to add some more conditions in my SP

Please help me in this
Thank you all

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-05-18 : 14:02:49
Rather than us doing all of the work, please post what you have tried so far. I'll give you an example:

select t1.a, t2.b, t1.c, t3.d
from table1 t1
inner join table2 t2
on t1.somecolumn = t2.somecolumn
inner join table3 t3
on t2.someothercolumn = t3.someothercolumn
where t1.z = 2

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

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-05-18 : 14:40:04
The best approach to write queries for complex problems is to divide the problem into smaller tasks.

1. Put the columns which you want to have as a part of result, in the SELECT part
2. See to which tables these columns belong and write down those tables in the FROM clause
3. See which columns are common between two tables. Join those tables based on common columns.
4. Put additional conditions as a part of WHERE clause.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

reflex2dotnet
Yak Posting Veteran

99 Posts

Posted - 2007-05-18 : 15:09:42
Thanks to Tara and Harsh
I am very happy yo say here that, i learned to write queiris using inner join(atleast simple ones)
This is only because i followed your example and your explanation

Thanks a lot
Go to Top of Page
   

- Advertisement -