• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 82
  • Last Modified:

Case Statement in SQL Delminted Query

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
metalteck
Asked:
metalteck
1 Solution
 
sdstuberCommented:
is this for oracle?

and, do you want the result to be left padded, right padded, centered, other?
0
 
metalteckAuthor Commented:
Yes, its for oracle and left padded is ok.
0
 
PortletPaulCommented:
LPAD( case expression ... end, 20 )

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

RPAD() is for right padding
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
DavidSenior Oracle Database AdministratorCommented:
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
 
metalteckAuthor Commented:
@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
 
awking00Commented:
What is the data type and scale of emp.emp_status?
0
 
metalteckAuthor Commented:
Emp Status is Char and 2 byte
0
 
awking00Commented:
So should those values show up at positions 1:2 or 19:20 for your vendor?
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now