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

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 join between two different formats
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

kond.mohan
Posting Yak Master

India
194 Posts

Posted - 05/24/2013 :  02:01:12  Show Profile  Reply with Quote
hi all
i need to join two date fields from 2 different tables
table1 yearmonth(nvarchar(255),null) 2013-jan
table2 invoicedate(datetime,null) 2012-12-31 00:00:00.000
and table.yearmonth is my input parameter

i am trying possible ways .pls help on this

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 05/24/2013 :  02:11:19  Show Profile  Reply with Quote
so for yearmonth do you want it to be joined to every day of the year from the other table?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

kond.mohan
Posting Yak Master

India
194 Posts

Posted - 05/24/2013 :  02:23:25  Show Profile  Reply with Quote
hi

yearmonth field need to join everymonth of second table

mohan
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 05/24/2013 :  02:54:18  Show Profile  Reply with Quote
sorry that doesnt make sense. You already have month coming in yearmonth field. What do you mean by
yearmonth field need to join everymonth of second table

how can record of 2013-Jan be linked to other months like Feb,Mar etc? whats the rule for that?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

djj55
Constraint Violating Yak Guru

USA
333 Posts

Posted - 05/24/2013 :  07:58:56  Show Profile  Reply with Quote
The preformance of this will be bad but you might try:
SELECT ...
FROM Table1 
INNER JOIN Table2 
    ON Table1.yearmonth = CAST(YEAR(Table2.invoicedate) AS VARCHAR(4)) + '-' + CONVERT(VARCHAR(3), Table2.invoicedate, 100)



djj
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.14 seconds. Powered By: Snitz Forums 2000