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
 Combining Tables

Author  Topic 

cekirge
Starting Member

4 Posts

Posted - 2006-02-02 : 09:56:42
Hello,
I have two tables that I would like to combine but with some rules.
Table 1 has two columns with Actual Time and Actual People
Table 2 has two columns also with Planned Time and Planned People

I would like to combine these two tables if the actual time is not more than 30 minutes from a planned time
If I use one of the planned times, i would not want to show it again, even if there is another actual time that is not more than 30 minutes of it.

For ex.
Planned Time has 20:00,23:00
Planned People has 2,5

Actual Time has 19:00,19:30,19:45,21:15
Actual People has 5,2,5,3

Output should be like
Planned_Time,Actual_Time,Planned_People,Actual_People
,19:00,,5
20:00,19:30,2,2
,19:45,,5
,21:15,,3
23:00,,5,

I can do this in asp but if this can be done in sql it would be better.
Any ideas appreciated.
Thanks.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-02-02 : 18:29:47
What is the PK for these 2 tables ? Post the table structure

----------------------------------
'KH'


Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-02-03 : 01:10:38
>>I can do this in asp but if this can be done in sql it would be better.

Then why do you want to do in SQL?

Madhivanan

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

cekirge
Starting Member

4 Posts

Posted - 2006-02-03 : 15:49:31
quote:
Originally posted by madhivanan

>>I can do this in asp but if this can be done in sql it would be better.

Then why do you want to do in SQL?

Madhivanan

Failing to plan is Planning to fail


I want to use the summarize the information and use it on the other pages.
quote:
Originally posted by khtan
What is the PK for these 2 tables ? Post the table structure



Is this what you were looking for, both tables have the same structure
0 Planned_Time datetime 8 -1
1 Planned_People tinyint 1 -1

Thanks
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-02-03 : 17:38:52
You mean you table has only 2 columns ? Then how do you determine which planned data is related to which actual data ? Can you also explain more on how to obtain the result ?
Aslo refer to this
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

----------------------------------
'KH'


Go to Top of Page
   

- Advertisement -