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.
| Author |
Topic |
|
rnonajr
Starting Member
1 Post |
Posted - 2009-12-17 : 11:56:45
|
I am trying to get all the data from the Spreads table where the Month of the meeting date in the contracts table is in the Months of the Spreads table the and the ContractYR are equal. When I run my queries separately they work fine, but when I run the combined it doesn't work. I'm sure it has something to do with the syntax but I can't figure it out.Following is my code and below that is a data example.select * from Spreads where Months LIKE (SELECT CAST(MONTH(Meeting_Date) AS CHAR) FROM Contracts WHERE Meeting_Date IS NOT null) Here is some data. My Spreads tableContractName ContractYR MonthsButterfly: 1xZQ Apr10:-2xZQ May10:1xZQ Jun10 10 4 5 6Butterfly: 1xZQ May10:-2xZQ Jun10:1xZQJul10 10 5 6 7Butterfly: 1xZQ Apr11:-2xZQ May11:1xZQ Jun11 11 4 5 6 10 and 11 are the contract years and my months column is of type CHAR now. Here is my Contracts tableContract Contract YR Meeting DateZQMar10 10 NULLZQApr10 10 NULLZQMay10 10 2010-05-21So in this instance I should get back basically all the info associated with the 1st two records of my spreads table because they have Months that are equal to 5 and their contract years are equal.I hope someone can help me.ThanksBob |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2009-12-17 : 12:10:49
|
Try thisselect a.*from Spreads ainner join Contracts b on a.ContractYR = b.[Contract YR] and a.Months = month(b.[Meeting Date]) |
 |
|
|
|
|
|