Solved

Case Statement in SQL Delminted Query

Posted on 2016-09-09
9
55 Views
Last Modified: 2016-09-15
I have the following case statement in my sql delimited query:
       ||(CASE
          WHEN emp.emp_status in ('FB','PN','PB','LW','LP','LS','LT','LE','LI','WA') THEN 'A'
          WHEN emp.emp_status in ('LF','LM','LO','LU','LA','LR') THEN 'L'
           ELSE null
          END

Although the result is just 1 character, per the vendor spec, it needs to be a length of 20.
How would I write that?
0
Comment
Question by:metalteck
9 Comments
 
LVL 73

Expert Comment

by:sdstuber
ID: 41791992
is this for oracle?

and, do you want the result to be left padded, right padded, centered, other?
0
 

Author Comment

by:metalteck
ID: 41792189
Yes, its for oracle and left padded is ok.
0
 
LVL 48

Accepted Solution

by:
PortletPaul earned 500 total points
ID: 41792267
LPAD( case expression ... end, 20 )

 By default lpad will add spaces up to the wanted length.

RPAD() is for right padding
0
 
LVL 23

Expert Comment

by:David
ID: 41792305
Hi MetalTech, I am simply curious about the business rule behind this fixed length field. It stirs memories of twentieth-century COBOL. Thanks for any insight.
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:metalteck
ID: 41792794
@dvz, its funny that you mention Cobol. the original program is written in program, but the specifics the vendor has asked for regarding the extract, I'm forced to use oracle sql.
The vendor's specs require that each specified field have a length as well as start and end position.
0
 
LVL 31

Expert Comment

by:awking00
ID: 41794453
What is the data type and scale of emp.emp_status?
0
 

Author Comment

by:metalteck
ID: 41794457
Emp Status is Char and 2 byte
0
 
LVL 31

Expert Comment

by:awking00
ID: 41794857
So should those values show up at positions 1:2 or 19:20 for your vendor?
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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
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

705 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

21 Experts available now in Live!

Get 1:1 Help Now