Click here to Skip to main content
15,353,432 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys

I have two tables tbl1 and tbl2 .

In tbl1 i have two columns Month and Year there both are numeric fileds.

and in tbl2 i have a columns named monthyear its data type is datetime and contains
dates .

What i want is to compare month and year part of this tbl2 monthyear column
with the combination of month and year column of the tbl1 .

e.g tbl1= Month Year
1 2010
7 2010

tbl2= monthyear
2010-01-31
2010-07-31

I want to get only those rows from tbl2 where monthyear column contains same
Month and Year in the tbl1 .
how can i make this comparison ?
any help ?
regards.
Posted
Updated 29-Sep-11 6:37am
v3

The title of your question is about .net but in the question you mention tables. So it isn't completely clear.

C# : DateTime.Year and DateTime.Month can be used to compare month and year value
T-SQL: YEAR and MONTH can be used.

Good luck!
   
v2
try this query...................


SQL
select t1.* from
tbl1 t1, tbl2 tbl2
where t1.month = convert(int, datepart(mm, t2.datecolumn)
and t1.year = convert(int, datepart(yyyy, t2.datecolumn)
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900