SQL 格式 ('MMMM') 在 SQL Server 2008 中不起作用
SQL Format('MMMM') does not work in SQL Server 2008
我有这个查询
select
format([time], 'MMMM') as 'Month',
count([time]) as 'Application Usage',
count([time]) as 'Application Usage'
from
UserLogs UL
where
[time] >= Dateadd(Month, Datediff(Month, 0, DATEADD(m, -6, current_timestamp)), 0)
and Ul.UserId = @user
group by
format([time],'MMMM')
但是我迁移到使用 SQL Server 2008 的服务器时出现此错误:
'format' is not a recognized built-in function name
我可以用什么来代替这个格式化功能?
SQL Server 2008 不支持 format()
。这里有一种互惠关系——Microsoft 不再支持 SQL Server 2008。
无论如何,只需使用datename()
:
select datename(month, [time]) as Month
这是 SQL Server 2012 及更高版本的功能。尝试 DATENAME(MONTH,[time]).
我有这个查询
select
format([time], 'MMMM') as 'Month',
count([time]) as 'Application Usage',
count([time]) as 'Application Usage'
from
UserLogs UL
where
[time] >= Dateadd(Month, Datediff(Month, 0, DATEADD(m, -6, current_timestamp)), 0)
and Ul.UserId = @user
group by
format([time],'MMMM')
但是我迁移到使用 SQL Server 2008 的服务器时出现此错误:
'format' is not a recognized built-in function name
我可以用什么来代替这个格式化功能?
SQL Server 2008 不支持 format()
。这里有一种互惠关系——Microsoft 不再支持 SQL Server 2008。
无论如何,只需使用datename()
:
select datename(month, [time]) as Month
这是 SQL Server 2012 及更高版本的功能。尝试 DATENAME(MONTH,[time]).