SQL Server like Statement add getdate + wildcard

ecbunoof  于 2023-04-10  发布在  SQL Server
关注(0)|答案(1)|浏览(157)

I want to replace the like statement with this function

select year(GetDate()) and add '%'

Can you help me how to do it?

Here is the SQL statement:

Select *
from table a 
where = month like '2023%'

I expect same result like the SQL statement, but replace with year(getdate()) statement.

ep6jt1vc

ep6jt1vc1#

First of all, I'm not sure whether string comparison makes sense in this case.
Nevertheless, I think you're looking for something like this (Convert to nvarchar and append %):

convert(nvarchar(4),year(GetDate())) +'%'

Full query:

Select *
from table a 
where month like convert(nvarchar(4),year(GetDate())) +'%'

相关问题