IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

SQL QUERY -- WHERE CLAUSE


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
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
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
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
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
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
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
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

Moderator Emeritus


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

PostPosted: Sat Jul 17, 2010 1:24 am
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts RC query -Time column CA Products 3
No new posts Dynamically pass table name to a sele... DB2 2
No new posts Query on edit primary command CLIST & REXX 5
No new posts Query on edit primary command CLIST & REXX 1
No new posts To search DB2 table based on Conditio... DB2 1
Search our Forums:

Back to Top