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

update record in sentence case


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
jeeva84

New User


Joined: 18 Apr 2008
Posts: 7
Location: India

PostPosted: Mon Jun 02, 2008 3:16 pm
Reply with quote

Hi,

I want a query to update all the record in a column in the following manner.

Input:
Column Name : City
Records:
NEW YORK
FLORIDA
ST. THOMAS
MIAMI-DADE


Requried output:
Column Mane : City
Records :
New York
Florida
St. Thomas
Miami-Dade
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Mon Jun 02, 2008 4:33 pm
Reply with quote

use this ...

Code:


UPDATE INPTABLE A SET CITY =
(SELECT LCASE(CITY) FROM INPTABLE B WHERE A.KEY = B.KEY);



this is a correlated full select being used for update .....
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Mon Jun 02, 2008 4:55 pm
Reply with quote

ashimer,

i don't understand how LCASE(CITY) will result in Miami, South Dakota, Miami-Dade?
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Mon Jun 02, 2008 5:00 pm
Reply with quote

You are right Dick ..i didnt notice that ...just took it to be updated using lower case ... thanks for the correction ...

here i guess you cannot do anything using a single query but will have to fetch each record and then manipulate the records and then update ...
Back to top
View user's profile Send private message
jeeva84

New User


Joined: 18 Apr 2008
Posts: 7
Location: India

PostPosted: Mon Jun 02, 2008 5:31 pm
Reply with quote

ok thnx Ashimer and Dick.
Is their any other way to achive this.
Back to top
View user's profile Send private message
nabarundas

New User


Joined: 21 Jun 2007
Posts: 28
Location: pune

PostPosted: Mon Jun 02, 2008 5:49 pm
Reply with quote

hi,

Try this:

SELECT CONCAT(SUBSTR(city,1,1),LCASE(SUBSTR(city,2)))
FROM <TableName>


Regards,
Nabarun
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Mon Jun 02, 2008 6:01 pm
Reply with quote

nabarundas,
nice try but no cigar: Miami-Dade, ST. THOMAS , New York

why do you think everyone has avoided this one?

I would suggest, as did Ashimer, use a cursor, select the field, manipulate it with a programming language then update.

you could write the program faster than generate the necessary complex sql.
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Tue Jun 03, 2008 3:38 pm
Reply with quote

Jeeva ,

this query will work as per your requirement provided only '.' and '-' will appear in city ..or else you may have to change the query as reqd ...

Code:


UPDATE INPTABLE SET CITY =
     CASE LOCATE('.',CITY)
      WHEN   0 THEN
        CASE LOCATE(' ',CITY)
           WHEN 0 THEN
             CASE LOCATE ('-',CITY)
                WHEN 0 THEN
                    SUBSTR(CITY,1,1) || LCASE(SUBSTR(CITY,2))
                ELSE
SUBSTR(CITY,1,1)||LCASE(SUBSTR(CITY,2,LOCATE('-',CITY)-2))||'-'
||SUBSTR(CITY,LOCATE('-',CITY)+1,1)||LCASE(SUBSTR(CITY,LOCATE('-',
CITY)+2))
                END
           ELSE
SUBSTR(CITY,1,1)||LCASE(SUBSTR(CITY,2,LOCATE(' ',CITY)-2))||' '
||SUBSTR(CITY,LOCATE(' ',CITY)+1,1)||LCASE(SUBSTR(CITY,LOCATE(' ',
CITY)+2))
           END
      ELSE
SUBSTR(CITY,1,1)||LCASE(SUBSTR(CITY,2,LOCATE('.',CITY)-2))||'.'
||SUBSTR(CITY,LOCATE('.',CITY)+1,1)||LCASE(SUBSTR(CITY,LOCATE('.',
CITY)+2))
     END;



as dick said this query might be a lil expensive and i wont recommend using this ... but as i had a lil free time today thot of writing this testing ...
consult with ur seniors before using this ...
Back to top
View user's profile Send private message
jeeva84

New User


Joined: 18 Apr 2008
Posts: 7
Location: India

PostPosted: Tue Jun 03, 2008 5:12 pm
Reply with quote

Thanks Ashimer.
Back to top
View user's profile Send private message
jeeva84

New User


Joined: 18 Apr 2008
Posts: 7
Location: India

PostPosted: Tue Jun 03, 2008 7:34 pm
Reply with quote

Now i got one more scenario. there are possibilities for three words.
For Example : KINGS AND QUEEN
The Expected Output is Kings And Queen.
For this i have to locate the second occurance of the space, is their any command in DB2
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Tue Jun 03, 2008 7:58 pm
Reply with quote

Not natively, as You might already have noticed...
just expand the logic provide by Ashimer

at the end the cheapest solution will certainly be to write a small program
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


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

PostPosted: Tue Jun 03, 2008 8:25 pm
Reply with quote

jeeva84 wrote:
Now i got one more scenario. there are possibilities for three words.
For Example : KINGS AND QUEEN
The Expected Output is Kings And Queen.
For this i have to locate the second occurance of the space, is their any command in DB2


Look at this thread ibmmainframes.com/viewtopic.php?t=31255&highlight=[/url]
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Tue Jun 03, 2008 8:28 pm
Reply with quote

Jeeva,

Change your 2nd ELSE part to

Code:


SUBSTR(CITY,1,1)||LCASE(SUBSTR(CITY,2,LOCATE(' ',CITY)-2))||' '
||SUBSTR(CITY,LOCATE(' ',CITY)+1,1)||LCASE(SUBSTR(CITY,LOCATE(' ',
CITY)+2,LOCATE(' ',CITY,LOCATE(' ',CITY)) - LOCATE (' ',CITY) + 3))
||SUBSTR(CITY,LOCATE(' ',CITY,LOCATE(' ',CITY)+1)+1,1)
||LCASE(SUBSTR(CITY,LOCATE(' ',CITY,LOCATE(' ',CITY)+1)+2))



Now what will you do if there are 3 spaces within the variable you will have to expand this query and it will go on ....

Similarly if your city has value S.T.THOMAS again you need to change for this part too ... which will make the query more and more expensive ... so better handle these conditions programmatically
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 How to split large record length file... DFSORT/ICETOOL 10
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts FINDREP - Only first record from give... DFSORT/ICETOOL 3
No new posts To find whether record count are true... DFSORT/ICETOOL 6
Search our Forums:

Back to Top