Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL case if field has a space?

Posted on 2009-04-09
5
Medium Priority
?
276 Views
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?
CASE(REVISION_ID)
 
              WHEN NULL THEN ' REV. -'
 
	      ELSE ' REV. ' + REVISION_ID
          
              END

Open in new window

0
Comment
Question by:D4430
[X]
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
5 Comments
 
LVL 25

Accepted Solution

by:
reb73 earned 1000 total points
ID: 24110010
Like this?

CASE(REVISION_ID)
               WHEN NULL THEN ' REV. -'
              WHEN ' ' THEN ' REV. -'
              ELSE ' REV. ' + REVISION_ID
END
0
 
LVL 39

Assisted Solution

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


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

to:
else revision_id
0
 

Author Comment

by:D4430
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?
0
 
LVL 25

Expert Comment

by:reb73
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..
0
 

Author Closing Comment

by:D4430
ID: 31568664
Thanks for your help today.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

722 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