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

numeric (NULL/Blank) > Text

Posted on 2009-07-15
2
359 Views
Last Modified: 2012-08-14
Hi Experts,

Need to convert numeric to text such that if NULL or blank it takes up a space

This works if @int is NOT:

SET @int = NULL
SET @int = ''

SELECT coalesce(convert(varchar(10), @int),'')

TIA!
0
Comment
Question by:allanau20
2 Comments
 
LVL 18

Accepted Solution

by:
philipjonathan earned 250 total points
ID: 24865792
To handle when int is NULL, insert a space in between the last argument:
SELECT coalesce(convert(varchar(10), @int),' ')

If @int is numeric type, it couldn't be ' ', so you don't need to worry about that
0
 
LVL 5

Author Comment

by:allanau20
ID: 24872653
Thanks -- just need to tweak it abit.

SELECT coalesce(convert(CHAR(10), @int), SPACE(10))
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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

808 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