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)
 Comparing two tables with condition.

Author  Topic 

ggmis
Starting Member

4 Posts

Posted - 2007-11-10 : 07:57:45
Hello everybody,
I need to query two tables in the same database (tableA, TableB) that contains records of Phone Number dialed (Numbercalled)and the time the numbers were dilaed (DateCalled). Match should be found when tables have rows w the same phone number and the difference in time no more than 60 seconds. Datecalled is the form:yyyy-mm-dd hh-mm-ss.
Something like: tableA.numberdialedA=tableB.numberdialedB AND DATEDIFF(second, DatecalledA, DateCalledB)<=60.

Really wish you can help me!!

thank you!!

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-11-10 : 08:00:04
[code]select *
from tableA inner join tableB
ON tableA.numberdialedA INNER JION = tableB.numberdialedB
where abs(DATEDIFF(second, DatecalledA, DateCalledB)) <= 60
[/code]

[EDIT] : C&P Error

KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

ggmis
Starting Member

4 Posts

Posted - 2007-11-10 : 10:20:11
Ktan,
thank you first for your idea...
I am using SQL 2k and I am not sure I can use such syntax: from tableA.numberdialedA = tableB.numberdialedB ...unless follows the name of the table.
What do you think?
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-11-10 : 11:02:22
oops


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

ggmis
Starting Member

4 Posts

Posted - 2007-11-12 : 09:11:21
Kh,
you query gives me the error:

Server: Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'inner'.

Any idea?
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-11-12 : 09:18:56
Just edited the query.


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

ggmis
Starting Member

4 Posts

Posted - 2007-11-12 : 09:52:58
Thank you!!!
Go to Top of Page
   

- Advertisement -