The data in the table well_summary.yearmonth is defined as varchar(7) - I need to retrieve the previous month, get the current year & use those variables in a select to retrieve the previous month's data. I have formed the following select, but get an error with the "+" trying to add the '/' for the date. can someone help me correct the select?
thanks
select CAST(DATEPART(m, getdate())-1 AS VARCHAR(2)) /*last month*/
SELECT CAST(DATEPART(YYYY, GETDATE()) AS VARCHAR(4))
UNION
SELECT Wells.APICode, Well_Summary.YearMonth
FROM Wells
CROSS JOIN Well_Summary
WHERE (Well_Summary.YearMonth = CAST(DATEPART(YYYY, GETDATE()) as varchar(2) + '/' + CAST(DATEPART(m, getdate())-1 as varchar(4) )