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: 1278
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 INVALID FIELD OR CONSTANT IN SORTOF ?? Ron Klop DFSORT/ICETOOL 8 Wed Jan 11, 2017 3:44 pm
No new posts Performing arithmetic on input field zh_lad DFSORT/ICETOOL 31 Tue Dec 06, 2016 8:04 pm
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts SQZ pipe delimited file with 1 column... Rick Silvers DFSORT/ICETOOL 2 Sun Nov 06, 2016 8:11 pm
No new posts Joinkeys operation when key1 and key2... Susanta DFSORT/ICETOOL 5 Wed Nov 02, 2016 5:35 pm


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