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
 

 

Trouble in executing query

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

New User


Joined: 10 May 2010
Posts: 32
Location: Mumbai

PostPosted: Thu Mar 21, 2013 11:41 am    Post subject: Trouble in executing query
Reply with quote

Hello All ,

I am having a specific requirement wherein I need to fetch data from a table as :

Select Department , Salary , EmpNo , Project from Employee ;

Now my requirment is out of the above 4 columns ( mentioned in select clause ) any one of the field may have a valid value and another may have spaces for eg.

Department = D01
Empno = Spaces
Project = ABC
Salary = Spaces

My requirement is to fetch only those records for which Department is D01 and Proeject is ABC.

This data may keep on varying. For next record I may have Empno = ABC123 and Project = ABN and other fields as spaces ..this way various combinations is possible.

Now I am trying to use below query :

Select Department , Salary , EmpNo , Project from Employee
where
(Department = 'Valid value ' or Department > Spaces ) and
(Salary = 'Valid Value ' or Salary > Spaces ) and
(Empno ='Valid Value ' or Empno > spaces) and
(Project =' Valid Value ' or Project > spaces) ;

Above query is fetching all the records instead of fetching records on specific data present in host variables.

Can anyone please suggest a way to fullfill this requirement.

Regards,
Shweta.
Back to top
View user's profile Send private message

Gnanas N

Active Member


Joined: 06 Sep 2007
Posts: 785
Location: Chennai, India

PostPosted: Thu Mar 21, 2013 11:56 am    Post subject:
Reply with quote

Simply you can try with a Cursor to select all the rows (possibly, multi row-fetch) and fetch the rows & apply your space-checking logic inside the program.
Back to top
View user's profile Send private message
Shweta12j

New User


Joined: 10 May 2010
Posts: 32
Location: Mumbai

PostPosted: Thu Mar 21, 2013 12:12 pm    Post subject: Reply to: Trouble in executing query
Reply with quote

Hi Gnanas N ,

I used the same query mentioned in my above post in cursor however I am not getting desired results as per the values mentioned in host variable.

I also examined an option of fetching all the rows in working storage variable and then comparing each..but then this won't work as a table would have load of data.

Regards,
Shweta.
Back to top
View user's profile Send private message
Gnanas N

Active Member


Joined: 06 Sep 2007
Posts: 785
Location: Chennai, India

PostPosted: Thu Mar 21, 2013 12:31 pm    Post subject:
Reply with quote

Please post some sample input values and the result of the query.
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1278
Location: Belgium

PostPosted: Thu Mar 21, 2013 1:59 pm    Post subject:
Reply with quote

it should be :
Code:
(:HV = Spaces or Department = :HV ) and ...


I'm not sure coalesce accept host-variabes as input, and I haven't tried this, because it's been ages since I compiled a program here, but this might also work :
Code:
(Department = coalesce(:HV:HVind,Department) )
as long as you fill :HVind with -1 when :HV = spaces
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 Executing OO COBOL program invoking J... Virendra Shambharkar COBOL Programming 2 Tue Jan 10, 2017 6:37 pm
This topic is locked: you cannot edit posts or make replies. MQ setup query mohitsaini Java & MQSeries 4 Sun Jan 08, 2017 1:53 am
No new posts DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
No new posts Viewing executing process in NDM .. q... Debb.Brant IBM Tools 0 Wed Dec 14, 2016 10:55 pm
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am


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