IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Using Length field in DB2 SQL


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
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
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
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
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Store the data for fixed length COBOL Programming 1
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts VB to VB copy - Full length reached SYNCSORT 8
Search our Forums:

Back to Top