The data in the table well_summary.ye armonth 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(Y YYY, GETDATE()) AS VARCHAR(4))
UNION
SELECT Wells.APICode, Well_Summary.Ye arMonth
FROM Wells
CROSS JOIN Well_Summary
WHERE (Well_Summary.Y earMonth = CAST(DATEPART(Y YYY, GETDATE()) as varchar(2) + '/' + CAST(DATEPART(m , getdate())-1 as varchar(4) )
thanks
select CAST(DATEPART(m , getdate())-1 AS VARCHAR(2)) /*last month*/
SELECT CAST(DATEPART(Y YYY, GETDATE()) AS VARCHAR(4))
UNION
SELECT Wells.APICode, Well_Summary.Ye arMonth
FROM Wells
CROSS JOIN Well_Summary
WHERE (Well_Summary.Y earMonth = CAST(DATEPART(Y YYY, GETDATE()) as varchar(2) + '/' + CAST(DATEPART(m , getdate())-1 as varchar(4) )
Comment