Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist 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: 788
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: 788
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: 1281
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 query to fetch record which has only ... maxsubrat DB2 12 Mon Dec 11, 2017 5:03 pm
No new posts How to query MAXGENS of an existing P... Chuchulo Hatyzak JCL & VSAM 4 Wed Nov 22, 2017 10:23 pm
No new posts Native SQL Query kishpra DB2 1 Wed Nov 22, 2017 8:38 pm
No new posts Query on IEFBR14 with GDG Ashishpanpaliya JCL & VSAM 4 Tue Nov 07, 2017 8:34 pm
No new posts Query on XMITIP abdulrafi All Other Mainframe Topics 1 Wed Oct 25, 2017 6:54 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us