问题描述
大家好
我有两个表tbl1和tbl2.
在tbl1中,我有两列Month和Year,它们都是数字字段.
在tbl2中,我有一个名为monthyear的列,其数据类型为datetime并包含
日期.
我想要的是比较此tbl2 monthyear列的月份和年份部分
与tbl1的month and year列的组合.
例如tbl1 =月份年份
2010年1月1日
7 2010
tbl2 = monthyear
2010-01-31
2010-07-31
我只想从tbl2中获取其中monthyear列包含相同内容的行
tbl1中的月份和年份.
我该如何进行比较?
有帮助吗?
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.
推荐答案
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)
这篇关于将整数转换为日期时间并进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!