Pranav Raj
Pranav Raj

Reputation: 873

Get the SQL Server version to a variable in bash script

I want to get the SQL Server version into a variable in my bash script.

I tried using

sqlcmd -S localhost -U SA -Q 'select @@VERSION'

but it returns a string containing a bunch of other information too - eg: the copyright information, 86/x64? etc.

What is the correct way to get just the version?

Upvotes: 1

Views: 525

Answers (1)

Mitch Wheat
Mitch Wheat

Reputation: 300719

Depends what you mean by 'SQL Server Version', but if you mean the build number:

sqlcmd -S localhost -U SA -Q "SELECT CAST(SERVERPROPERTY('ProductVersion') AS NVARCHAR(128))"

Example output:

13.0.5081.1

Upvotes: 4

Related Questions