I'm trying to automate a short task in configuring our SQL Server for which I have to grab SQL Server year. Is there a way to extract year only from the output of following query:
Select @@version ?
As you know it outputs the whole informatioin e.g.: Microsoft SQL Server 2017 (RTM-CU18) (KB4527377) - 14.0.3257.3 (X64) Nov 16 2019 01:14:50 Copyright (C) 2017 Microsoft Corporation Standard Edition (64-bit) on Windows Server 2016 Standard 10.0 (Build 14393: ) (Hypervisor)
I tried the year function as below but I'm getting conversion error.
declare @SQLVersion varchar(100) set @SQLVersion = (Select year(@@version)) print @SQLVersion
Or is there another way of grabbing the year only using tsql?
Any help is appreciated.