SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Check Datetime Existence within multiple columns
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

6 Posts

Posted - 01/23/2013 :  06:57:20  Show Profile  Reply with Quote
Hi there,

I've a BillDate as date, and a Mark as bit column in First table.
(Mark=0 by default)

In Second table I've FromDate as date, and ToDate as date Column.

I want to set Mark=1 if BillDate is exists between FromDate & ToDate

Let Say In First Table the data is
BillDate | Mark
2012-11-10 11:15:30 | 0
2012-12-12 09:00:00 | 0

In Second Table the data is
FromDate | ToDate
2012-11-01 07:00:00 | 2012-11-09 23:59:59
2012-12-08 07:00:00 | 2012-12-15 23:59:59

So in the above scenario only the second row from First table
which is having, BillDate->2012-12-12 09:00:00 will be Mark as 1
because it comes between second row of second table

I hope I've explained my scenario,

Very Important crosS Applying yaK Herder

52325 Posts

Posted - 01/23/2013 :  07:02:24  Show Profile  Reply with Quote

SET Mark=1
FROM table1 t1
JOIN table2 t2
ON t1.BillDate >= t2.FromDate
AND t1.BillDate <= t2.ToDate 

SQL Server MVP

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000