Solved

numeric (NULL/Blank) > Text

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Server 2012 r2 - Varible Table 3 25
Increment column based of a FK 8 23
performance query 4 24
SQL Syntax: How to force case sensitive query? 2 31
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
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
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

821 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