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)
 Tough Query(should i call this conditional join or something)

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-04-04 : 07:57:50
Sangram Patil writes "We are using Asp.NET & SQL SERVER 2000 to build a shoppingcart.

I dont know how to put it technically so i'll try my best explain its logic.

we have 2 tables Orders and SubOrders.

Orders table has 2 fields ID & Total.

SubOrders has 3 fields SID, OrderID & Details

The relationship b/n the 2 tables is Orders.ID=SubOrders.OrderID

the following is the sample data:

Orders
ID Total
----------
1 10
2 20

SubOrders
SID OrderID Details
----------------------------
1 1 Details1
2 1 Details2
3 2 Details3
4 2 Details4
5 2 Details5

Now we want to frame a query which returns results as follows.

RESULTS:
ID SID Details Total
----------------------------------------
1 1 Details1 10
2 1 Details2 00
3 2 Details3 20
4 2 Details4 00
5 2 Details5 00

I hope ypu guys have understood my Problem.
I have tried my best to explain it to you.

And thanks in advance"

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2005-04-04 : 08:31:41
I did not understand Your problem.
I think that You should not store Total in Orders table like You do.

If You join Orders & SubOrders given the sample data You WILL get:
ID SID Details Total
----------------------------------------
1 1 Details1 10
2 1 Details2 10
3 2 Details3 20
4 2 Details4 20
5 2 Details5 20


If that is not what You want, You have a bad design.

rockmoose
Go to Top of Page

mr_mist
Grunnio

1870 Posts

Posted - 2005-04-04 : 08:40:12
Indeed, I couldn't figure this one out. For the same ID you want to bring back a different total? Sorry but that makes no sense.

-------
Moo. :)
Go to Top of Page
   

- Advertisement -