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: 1280
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 SORT VSAM file with each field one by... maxsubrat DFSORT/ICETOOL 6 Tue Mar 14, 2017 1:07 pm
No new posts IMS DB-How to update a record (a sing... Nic Clouston IMS DB/DC 9 Thu Mar 09, 2017 4:38 pm
No new posts outrec field outside range Danielle.Filteau SYNCSORT 10 Sat Mar 04, 2017 2:37 am
No new posts Writing on to GSAM variable length rohanthengal JCL & VSAM 6 Fri Mar 03, 2017 7:46 pm
No new posts 2 byte YEAR from Y'DATE2' field tecnokrat DFSORT/ICETOOL 2 Tue Feb 07, 2017 12:05 pm


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