select eomonth('2023-01-01')
我希望函数MONTHNAME('2023-01-01')选取我的别名,这样输出将为2023-01-30,别名将为January
MONTHNAME('2023-01-01')
2023-01-30
January
laawzig21#
您可以使用日期名:
select eomonth('2023-01-01') ,DATENAME(MONTH, eomonth('2023-01-01') )
动态别名:
declare @yourdate date = '2023-01-01' declare @monthname nvarchar(20)=(select DATENAME(MONTH,@yourdate)) declare @SQL nvarchar(200) = concat('select eomonth(',quotename(@yourdate,char(39)),') as ',@monthname ) exec sp_executesql @SQL
添加您的查询:
declare @yourdate date = '2023-01-01' declare @monthname nvarchar(20)=(select DATENAME(MONTH,@yourdate)) declare @anothersql nvarchar(500) = ',COALESCE((SELECT SUM(deductdays) FROM tbl_LeaveDeduction WHERE CHARINDEX(quotename(CAST(EmpId AS varchar(10)),char(44)), @EmpIds) > 0 and DATEPART(MONTH,DeductionDate)= DATEPART(MONTH,@StartofYear) ),0)' declare @SQL nvarchar(500) = concat('select eomonth(',quotename(@yourdate,char(39)),') as ',@monthname,@anothersql ) exec sp_executesql @SQL
1条答案
按热度按时间laawzig21#
您可以使用日期名:
动态别名:
添加您的查询: