Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Convert a sql_variant value to a varchar

Posted on 2009-05-06
2
9,009 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

766 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