Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

numeric (NULL/Blank) > Text

Posted on 2009-07-15
2
Medium Priority
?
372 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 1000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
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 the fundamental information of how to create a table.

772 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