Sql server 检索员工上个月/期间的数据

Sql server 检索员工上个月/期间的数据,sql-server,Sql Server,我在sql server表中有一个字段,在其中我将员工的月份和年份存储在varchar数据类型中。。。比如2016年1月 现在,我正在尝试从表中检索某个特定员工上个月(格式为月-年)的数据,即多个月中的2016年1月 请向我推荐任务的sql查询?????相对于当前月份或上个月员工工作的前几个月? --As last month value is static, so lets store it in variable and then use it in where clause. declar

我在sql server表中有一个字段,在其中我将员工的月份和年份存储在varchar数据类型中。。。比如2016年1月

现在,我正在尝试从表中检索某个特定员工上个月(格式为月-年)的数据,即多个月中的2016年1月


请向我推荐任务的sql查询?????

相对于当前月份或上个月员工工作的前几个月?
--As last month value is static, so lets store it in variable and then use it in where clause.
declare @LastMonth varchar(8)
SET @LastMonth = replace(right(convert(varchar(100), 
                                       dateadd(mm, -1, getdate()), 
                                       106)
                              , 8), ' ', '-'
                        )

select * from myTable
where dateCol =  @LastMonth