I have a table with dates that are about 1 month before the other table.
For example, one table reports 1st quarter end on March 31st and the other reports 1st quarter end on February 28th (or 29th) but it would be perfectly fine to join them together by the date regardless that the two dates arent exactly the same.
Any suggestions, please.
Thanks
5条答案
按热度按时间t1qtbnec1#
You can join on DateDiff(dd, Date1, Date2) < x
Or to get more exact
kognpnkq2#
Your ON clause could look at year and quarter for a match:
a1o7rhls3#
One approach would be to use the DATEPART() function that returns the
quarter
for any given date. Then you would be able to join on the returned quarter.Sample SQL:
Put any other fields as you require (ID fields most probably) in the internal SELECTS.
vjhs03f74#
If I rigthly understood you and you have the same number of column in those tables then you should use
UNION
in your SQL-query. See more information aboutUNION
here: http://en.wikipedia.org/wiki/Set_operations_%28SQL%29 .von4xj4u5#