Link to home
Start Free TrialLog in
Avatar of BravehearT-1326
BravehearT-1326Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Convert a sql_variant value to a varchar

Hi there  I'd like to be able to place the value returned from the command below into a varchar variable to use in a script but I am getting the error:

Implicit conversion from data type sql_variant to varchar is not allowed. Use the CONVERT function to run this query.

Ideally I'd like to have something like:

DECLARE @server varchar(50)

set @server = (select SERVERPROPERTY('MachineName') WindowsServerName)  whilst using the CONVERT function - can anyone help as I'm really new to TSQL programming.

Thanks

select SERVERPROPERTY('MachineName') WindowsServerName

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of pivar
pivar
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BravehearT-1326

ASKER

Many thanks for the speedy reply - your code works a treat...