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

To select records that name field start with only caps


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

New User


Joined: 02 Feb 2007
Posts: 5
Location: Chennai

PostPosted: Thu Sep 06, 2007 5:59 pm
Reply with quote

How to select the rows that having a name field only starts with capital letter?
Back to top
View user's profile Send private message
guptae

Moderator


Joined: 14 Oct 2005
Posts: 1208
Location: Bangalore,India

PostPosted: Thu Sep 06, 2007 6:10 pm
Reply with quote

Hi suresh,

Would you please provide the record length & type of input .
Please provide us sample input & output so that we can help u out
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Thu Sep 06, 2007 7:08 pm
Reply with quote

Since this is in the DB2 forum I will assume there is no record length and you are querying a database table. So you have a NAME column in your table.

Using only that column for illustration:

Code:

Name
----------
robert
larry
James
Thomas
richard
Mark


You want to select only those records that have a capital letter in position 1 of the data for that column and have the result set look like this?

Code:

James
Thomas
Mark


Did I summarize your problem correctly?
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


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

PostPosted: Thu Sep 06, 2007 7:17 pm
Reply with quote

You could use
Code:
SELECT * FROM TABLE WHERE (NAME BETWEEN 'A' AND 'I' ) OR (NAME BETWEEN 'J' AND 'R')  OR (NAME BETWEEN 'S' AND 'Z' );
 

or
Code:
SELECT * FROM TABLE WHERE SUBSTR(NAME,1,1) = UPPER(NAME,1,1);
 
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Thu Sep 06, 2007 7:22 pm
Reply with quote

Does DB2 do case sensitive comparisons by default or is there some option that needs to be switched? I had no idea so I didn't suggest your option 2. But that is how I would do it.
Back to top
View user's profile Send private message
TG Murphy

Active User


Joined: 23 Mar 2007
Posts: 148
Location: Ottawa Canada

PostPosted: Thu Sep 06, 2007 9:22 pm
Reply with quote

I like Craq's 2nd solution but it may not work if the field starts with a number or some other character that has no uppercase equivilant.

Would the following tweak fix this?

Code:

SELECT * FROM TABLE WHERE SUBSTR(NAME,1,1) = UPPER(NAME,1,1)
        AND UPPER(SUBSTR(NAME,1,1)) <> LOWER(SUBSTR(NAME,1,1)
 


Craq's first solution seems fine...
Back to top
View user's profile Send private message
sureshbait
Warnings : 1

New User


Joined: 02 Feb 2007
Posts: 5
Location: Chennai

PostPosted: Fri Sep 07, 2007 1:22 pm
Reply with quote

Thank you Craq.

I tried both queries first one is working. 2nd one is not working.
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


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

PostPosted: Fri Sep 07, 2007 5:14 pm
Reply with quote

sureshbait wrote:
Thank you Craq.

I tried both queries first one is working. 2nd one is not working.


My error should be
Code:
SELECT * FROM TABLE WHERE SUBSTR(NAME,1,1) = UPPER(substr(NAME,1,1));
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 Compare 2 files and retrive records f... DFSORT/ICETOOL 2
No new posts Compare 2 files(F1 & F2) and writ... JCL & VSAM 8
No new posts Compare only first records of the fil... SYNCSORT 7
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
Search our Forums:

Back to Top