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

Selecting Like values for a nemeric data type column


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
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
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
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
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: 275
Location: Bang,iflex

PostPosted: Thu Nov 15, 2007 3:55 pm
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
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

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Thu Nov 15, 2007 6:11 pm
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts How to save SYSLOG as text data via P... All Other Mainframe Topics 2
No new posts Replacing 'YYMMDD' with date, varying... SYNCSORT 3
No new posts Store the data for fixed length COBOL Programming 1
No new posts INCLUDE OMIT COND for Multiple values... DFSORT/ICETOOL 5
No new posts Data set Rec-Cnt and Byte-Cnt Testing & Performance 2
Search our Forums:

Back to Top