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
 
SQL QUERY -- WHERE CLAUSE

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

New User


Joined: 16 Jul 2010
Posts: 2
Location: india

PostPosted: Fri Jul 16, 2010 11:28 pm    Post subject: SQL QUERY -- WHERE CLAUSE
Reply with quote

Hi friends,
one question.. stupid may be icon_smile.gif

i have one sql query...

Select c1, c2
from t1, t2
where t1.name = t2.name

now in above query if u want to add one more condition in where clause like below

Select c1, c2
from t1, t2
where t1.name = t2.name
and variableA = variableB

where variableA and variableB are host variables and not db2 columns.
is it acceptable?

thanks for the help!
Back to top
View user's profile Send private message

Craq Giegerich

Senior Member


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

PostPosted: Fri Jul 16, 2010 11:34 pm    Post subject: Re: SQL QUERY -- WHERE CLAUSE
Reply with quote

lr23307 wrote:
Hi friends,
one question.. stupid may be icon_smile.gif

i have one sql query...

Select c1, c2
from t1, t2
where t1.name = t2.name

now in above query if u want to add one more condition in where clause like below

Select c1, c2
from t1, t2
where t1.name = t2.name
and variableA = variableB

where variableA and variableB are host variables and not db2 columns.
is it acceptable?

thanks for the help!


If it coded properly it will work but why not just compare the host variables in you program and avoid the extra overhead and cost of calling DB2 to do it? If they don't match then you would not have to call DB2 at all.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6970
Location: porcelain throne

PostPosted: Fri Jul 16, 2010 11:36 pm    Post subject:
Reply with quote

Quote:
is it acceptable?


no, the compare should be done outside of the sql,
in your programming language,
and only if equal should you invoke your original sql.

it is a waste of db2 resources.

now,
is it valid sql?

yes,
as long as you precede the host variables with the syntax required colon - :.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6970
Location: porcelain throne

PostPosted: Fri Jul 16, 2010 11:38 pm    Post subject:
Reply with quote

i am a little slow tonight, Craig.
Back to top
View user's profile Send private message
lr23307

New User


Joined: 16 Jul 2010
Posts: 2
Location: india

PostPosted: Sat Jul 17, 2010 12:04 am    Post subject:
Reply with quote

thank u friends.... actually the requirement is such that ... so i wanted to confirm.... i will run in mainframe and make sure from my end as well.. thanks for the help.. appreciate.. have a nice weekend.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6970
Location: porcelain throne

PostPosted: Sat Jul 17, 2010 1:01 am    Post subject:
Reply with quote

lr23307 wrote:
thank u friends.... actually the requirement is such that ... so i wanted to confirm.... i will run in mainframe and make sure from my end as well.. thanks for the help.. appreciate.. have a nice weekend.


i interpret that as:
well, since I can do it, I'm gonna, yuk-yuk!
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Sat Jul 17, 2010 1:24 am    Post subject:
Reply with quote

Hello and welcome to the forum,

Quote:
actually the requirement is such that
No it is not the requirement. The requirement is to correctly solve the business need.

You may have someone in your organization that believes coding preferences of clueless people constitutes a requirement, but it does not. Why would someone believe that doing simple code via the database management software was even acceptable let alone required. . . icon_confused.gif

Quote:
is it acceptable?
Not by any proper development standard. . . It is a poor choice for implementation. Another of the things that "can be done", but should not be done.
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 Date in where clause - Windows Karthikeyan Subbarayan DB2 9 Wed Nov 15, 2017 9:07 pm
No new posts Query on IEFBR14 with GDG Ashishpanpaliya JCL & VSAM 4 Tue Nov 07, 2017 8:34 pm

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