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: 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 JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm
No new posts SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm
No new posts Omegamon for DB2 query ashek15 DB2 0 Wed Feb 15, 2017 11:25 am
No new posts Query on DB2 WLM stored procedures ashek15 DB2 8 Sun Feb 12, 2017 11:13 pm
No new posts GETMAIN/FREEMAIN query Suja.Sai CICS 9 Tue Jan 31, 2017 12:01 pm


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