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
 

 

Selecting Like values for a nemeric data type column

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
geeta.mishra

New User


Joined: 27 Dec 2005
Posts: 21
Location: Bangalore

PostPosted: Wed Nov 14, 2007 6:59 pm    Post subject: Selecting Like values for a nemeric data type column
Reply with quote

Hi,
I have a column in the table which has the data type as SMALLINT.
This column is used in the WHERE clause of the query. I want to select :
1.the matching rows for the given value of this column
2.All the rows from the table (irrespective of the value of this column).

As this is not a character column I can not use the LIKE clause to do the same.

Is there any way I can serve both of the above purposes altogether in a single query?

e.g.
SELECT column1,column2
FROM table1
WHERE
column3 = 1

SELECT column1,column2
FROM table1
WHERE
column3 LIKE '%%%'

The syntax used in the second query is not correct. can I have a solution for this?

Thanks,
Geeta
Back to top
View user's profile Send private message

Craq Giegerich

Senior Member


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

PostPosted: Wed Nov 14, 2007 7:27 pm    Post subject: Re: Selecting Like values for a nemeric data type column
Reply with quote

geeta.mishra wrote:
e.g.
SELECT column1,column2
FROM table1
WHERE
column3 = 1

SELECT column1,column2
FROM table1
WHERE
column3 LIKE '%%%'

The syntax used in the second query is not correct. can I have a solution for this?

Thanks,
Geeta


How about
Code:
SELECT COLUMN1, COLUMN2 FROM TABLE1
Back to top
View user's profile Send private message
geeta.mishra

New User


Joined: 27 Dec 2005
Posts: 21
Location: Bangalore

PostPosted: Thu Nov 15, 2007 3:42 pm    Post subject: Reply to: Selecting Like values for a nemeric data type colu
Reply with quote

Hi,
I dint understand the reply.
Could you please explain?


Regards,
Geeta
Back to top
View user's profile Send private message
vasanthkumarhb

Active User


Joined: 06 Sep 2007
Posts: 276
Location: Bang,iflex

PostPosted: Thu Nov 15, 2007 3:55 pm    Post subject:
Reply with quote

Hi,


Hi,

Quote:
I have a column in the table which has the data type as SMALLINT.
This column is used in the WHERE clause of the query. I want to select :
1.the matching rows for the given value of this column
2.All the rows from the table (irrespective of the value of this column).

As this is not a character column I can not use the LIKE clause to do the same.

Is there any way I can serve both of the above purposes altogether in a single query?


According to your requirementas stated above.


Code:
SELECT COLUMN1, COLUMN2 FROM TABLE1


The above query is correct, why you are using column3 = 1 in the first query and wild charecter in second query "%" this is my concern pls give more info.
Back to top
View user's profile Send private message
geeta.mishra

New User


Joined: 27 Dec 2005
Posts: 21
Location: Bangalore

PostPosted: Thu Nov 15, 2007 5:41 pm    Post subject: Selecting Like values for a nemeric data type column
Reply with quote

I think I cudnt put my requirement adequately.

There is a column 'column3' in a table 'table1' which has data type as
Numeric.My requirement is I have to select the rows from the table based on the following conditions:
1.I want to select records from table1 based on the value of column3.
2.I want to select all the records from table 1 regardless of the value of column3 i.e. all the rows from the table will be selected.

If you see 2 queries can be written to serve the above purpose as I have mentioned.
query 1 will select from the table 'table1' and use 'column3' in the Where clause
query2 will select from the table 'table' without using the where clause.
But my requrement is to use a single query which can serve both of the purposes.


Let me know if still you did not get me.
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10210
Location: italy

PostPosted: Thu Nov 15, 2007 6:11 pm    Post subject: Reply to: Selecting Like values for a nemeric data type colu
Reply with quote

the column content and type is irrelevant for Your request...

since the result of a query rerieving all the rows is from a logical point of view
always a superset of a query with a "WHERE" clause ....

why would You want to complicate Your life with a useless additional constraint ???
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 Nov 15, 2007 6:42 pm    Post subject: Re: Selecting Like values for a nemeric data type column
Reply with quote

geeta.mishra wrote:
I think I cudnt put my requirement adequately.

There is a column 'column3' in a table 'table1' which has data type as
Numeric.My requirement is I have to select the rows from the table based on the following conditions:
1.I want to select records from table1 based on the value of column3.
2.I want to select all the records from table 1 regardless of the value of column3 i.e. all the rows from the table will be selected.

If you see 2 queries can be written to serve the above purpose as I have mentioned.
query 1 will select from the table 'table1' and use 'column3' in the Where clause
query2 will select from the table 'table' without using the where clause.
But my requrement is to use a single query which can serve both of the purposes.


Let me know if still you did not get me.


If you are saying that sometimes you want to use the where and sometimes you do not then try this:

Code:
01  ws-min pic s9(4) comp-5.
01  ws-max pic s9(4) comp-5.

SELECT COLUMN1, COLUMN2 FROM TABLE1
WHERE COLUMN3 BETWEEN :WS-MIN AND :WS-MAX

If you have a value for column3 move it to ws-min and ws-max, else MOVE -32768 TO WS-MIN.
MOVE 32767   TI WS-MAX.
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 Storing huge volume of data, compare ... Pradeep K M All Other Mainframe Topics 3 Mon Jan 16, 2017 5:08 pm
No new posts how to recover an uncataloged VSAM da... archanamuthukrishnan All Other Mainframe Topics 3 Wed Jan 11, 2017 6:18 pm
No new posts DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
No new posts HALDB data refresh/copy from producti... vineetanand2007 IMS DB/DC 0 Mon Jan 02, 2017 11:16 am
No new posts JES2 JEC: Use UNIX Pipes to Pass Data... Virendra Shambharkar JCL & VSAM 21 Tue Dec 20, 2016 6:55 pm


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