Solved

numeric (NULL/Blank) > Text

Posted on 2009-07-15
2
355 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now