Solved

Convert a sql_variant value to a varchar

Posted on 2009-05-06
2
8,708 Views
Last Modified: 2012-05-06
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

0
Comment
Question by:BravehearT-1326
2 Comments
 
LVL 22

Accepted Solution

by:
pivar earned 50 total points
ID: 24316170
Hi,

How about

DECLARE @server varchar(50)
select @server = CONVERT(varchar(50),SERVERPROPERTY('MachineName'))
select @server

/peter
0
 

Author Closing Comment

by:BravehearT-1326
ID: 31578523
Many thanks for the speedy reply - your code works a treat...  
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question