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)
 Query Help

Author  Topic 

hisouka
Starting Member

28 Posts

Posted - 2007-08-04 : 01:43:43

I have to Tables:

CAR1
Anumber.......BNumber.......CallDate.......CallTime.......Duration
330...............44932........20060101........07:30............5
330...............44932........20060101........12:46............125
330...............44932........20060101........23:12............25


CAR2
Anumber.......BNumber.......CallDate.......CallTime.......Duration
330...............44932........20060101........07:15............5
330...............44932........20060101........12:36............122
330...............44932........20060101........23:01............28


I Want to match Record from CAR1 to CAR2 with Exact Matching Criterea of ANumber, BNumber and CallDate...

CallTime and Duration must match even not exactly but with the nearest value...

jonasalbert20
Constraint Violating Yak Guru

300 Posts

Posted - 2007-08-04 : 02:53:39
See this post. it may help.

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=87226

and ...

http://www.sqlservercentral.com/forums/shwmessage.aspx?forumid=8&messageid=387610











Want Philippines to become 1st World COuntry? Go for World War 3...
Go to Top of Page

hisouka
Starting Member

28 Posts

Posted - 2007-08-04 : 03:11:41
THis is my detailed question...

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1962500&SiteID=1
Go to Top of Page

hisouka
Starting Member

28 Posts

Posted - 2007-08-25 : 00:43:53
quote:
Originally posted by hisouka

THis is my detailed question...

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1962500&SiteID=1



Any idea??? thanks
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-08-25 : 04:04:53
You should reconsider having DATE and TIME in different columns.
-- Prepare sample data
DECLARE @Car1 TABLE (aNumber INT, bNumber INT, CallDate SMALLDATETIME, CallTime SMALLDATETIME, Duration INT)

INSERT @Car1
SELECT 330, 44932, '20060101', '07:30',5 UNION ALL
SELECT 330, 44932, '20060101', '12:46', 125 UNION ALL
SELECT 330, 44932, '20060101', '23:12', 25

DECLARE @Car2 TABLE (aNumber INT, bNumber INT, CallDate SMALLDATETIME, CallTime SMALLDATETIME, Duration INT)

INSERT @Car2
SELECT 330, 44932, '20060101', '07:15', 5 UNION ALL
SELECT 330, 44932, '20060101', '12:36', 122 UNION ALL
SELECT 330, 44932, '20060101', '23:01', 28

-- Show the expect output
SELECT c1.aNumber,
c1.bNumber,
c1.CallDate,
c1.CallTime AS c1time,
c1.Duration AS c1duration,
c2.CallTime AS c2time,
c2.Duration AS c2duration
FROM @Car1 AS c1
INNER JOIN @Car2 AS c2 ON c2.aNumber = c1.aNumber
AND c2.bNumber = c1.bNumber
AND c2.CallDate = c1.CallDate
AND c2.CallTime = (SELECT TOP 1 c2.CallTime FROM @Car2 AS c2 WHERE c2.aNumber = c1.aNumber AND c2.bNumber = c1.bNumber AND c2.CallDate = c1.CallDate ORDER BY ABS(DATEDIFF(MINUTE, c1.CallTime, c2.CallTime)))



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -