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
 

 

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: 6966
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: 6966
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: 6966
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 Join in SQL Query vickey_dw DB2 0 Tue Jan 17, 2017 12:15 am
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 SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm


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