Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Using Length field in DB2 SQL

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
Khwairakpam Raju Singh

New User


Joined: 05 Dec 2007
Posts: 29
Location: Bangalore

PostPosted: Mon Jul 26, 2010 9:16 pm    Post subject: Using Length field in DB2 SQL
Reply with quote

Hi All,
Could anyone help me out to form a SQL query for the following requirement?
I have a requirement where in I have to set the value of a column to space if the length of value present in the field is not equal to 2.

e.g.: the Value present in the field (say col_A) of a table (say tab_A) is 'A03' or 'A' then I have to update the value as space. On the other hand if the value is 'AB' (2 byte length). Then I have to keep as it is.

Please suggest me how to do in SQL. Thanks in advance.
Back to top
View user's profile Send private message

Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Mon Jul 26, 2010 9:19 pm    Post subject:
Reply with quote

Is this column defined as varchar?
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Mon Jul 26, 2010 9:25 pm    Post subject:
Reply with quote

if col_a is varchar then
update ... where length(col_a) <>2
else
update ... where length(strip(col_a)) <> 2 (if you define "length of value" as number of characters without trailing spaces )
Back to top
View user's profile Send private message
Khwairakpam Raju Singh

New User


Joined: 05 Dec 2007
Posts: 29
Location: Bangalore

PostPosted: Tue Jul 27, 2010 12:37 pm    Post subject:
Reply with quote

Oh!! Due to some misunderstanding, I was trying with LEN(), and I got and error.

now its working with the LENGTH() fuction :-) Thanks a lot for you help
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts READ A PACKED "NEGATIVE" FI... jdesouza CA Products 3 Tue May 02, 2017 11:43 pm
No new posts Alter &DATENS field in HEADER1 Angad DFSORT/ICETOOL 4 Mon Apr 24, 2017 11:49 am
No new posts Length of Tape file Mohan Kothakota JCL & VSAM 9 Thu Apr 20, 2017 10:24 pm
No new posts Sort Large record length cmsmoon DFSORT/ICETOOL 14 Tue Apr 11, 2017 5:49 pm
No new posts Count the length of the record & ... sreekusr DFSORT/ICETOOL 4 Thu Mar 23, 2017 7:52 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us