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: 1209
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: 631
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: 631
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 All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Format data from multiple records usi... SYNCSORT 4
No new posts Sort SMF records? SYNCSORT 6
No new posts To Sort detail records in a file with... SYNCSORT 5
No new posts Identify and write records containing... SYNCSORT 11
No new posts Filter records where condition is in ... SYNCSORT 6
Search our Forums:


Back to Top