Calculated date as column name SQL Server 2008 -
there numerous questions here naming column variable, don't believe duplicate of these, use calculation.
i name column after previous month. expect work:
select isnull(sum(case when datepart(mm,rc.datetime) = datepart(month, getdate()) -1 1 else null end),0) datename(mm, dateadd(mm, -1, getdate()))
or readability:
... datename(mm, dateadd(mm, -1, getdate()))
but not, incorrect syntax error. achievable? in advance given.
try dynamic sql,
declare @sql nvarchar(max) = '' set @sql = 'select isnull(sum(case when datepart(mm, rc.datetime) = ' + convert(varchar(10), datepart(month, getdate())) + ' - 1 1 else null end), 0) ' + datename(mm, dateadd(mm, - 1, getdate())) exec sp_executesql @sql
Comments
Post a Comment