SQL case if field has a space?

Posted on 2009-04-09
Last Modified: 2012-05-06
Hi. The code below works. The problem that I have is that there are some parts that have a space in the Revision_ID field. If there is a space I would like it to put REV. - in the field. How can I use a case to filter these?
              WHEN NULL THEN ' REV. -'
	      ELSE ' REV. ' + REVISION_ID

Open in new window

Question by:D4430
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
  • 2
  • 2
LVL 25

Accepted Solution

reb73 earned 250 total points
ID: 24110010
Like this?

               WHEN NULL THEN ' REV. -'
              WHEN ' ' THEN ' REV. -'
              ELSE ' REV. ' + REVISION_ID
LVL 39

Assisted Solution

BrandonGalderisi earned 250 total points
ID: 24110103
' REV. ' + CASE when REVISION_ID is null then '-'
                     when ltrim(revision_id) = '' then '-'
                     else ltrim(str(revision_id))

if revision_id is a NOT an int or other number field, change this:
else ltrim(str(revision_id))

else revision_id

Author Comment

ID: 24110121
Thanks it is now working when there is a space. I still need to refine it because if Revision_ID is null then the result is Null also. Any ideas?
LVL 25

Expert Comment

ID: 24110259
I believe you tried my solution, which won't quite work as WHEN NULL doesn't quite work as expected..

Try Brandon's solution (24110103) which should work..

Author Closing Comment

ID: 31568664
Thanks for your help today.

Featured Post

 Database Backup and Recovery Best Practices

Join Percona’s, Architect, Manjot Singh as he presents Database Backup and Recovery Best Practices (with a Focus on MySQL) on Thursday, July 27, 2017 at 11:00 am PDT / 2:00 pm EDT (UTC-7). In the case of a failure, do you know how long it will take to restore your database?

Question has a verified solution.

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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
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 information from SQL Server on Database, Connection and Server properties
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

617 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