Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing Where Condition in Sybase Store Procedure

Status
Not open for further replies.

moonoo

Programmer
May 17, 2000
62
0
0
US
Hi ,
I have a requirement like this . I have some 10 conditions in the where clause . And if some arguments are null , then the condition is not to be included in the where condotion.
I can write a if else conditon to build the query . But it will be diffrent queries.
like
If ( condition)
some sql query
else if ( some other condition)
some other sql .
Is it possible to build the query dynamically and execute the query in the end like i do in java ( where a single query does the job and dependng on the condition i add or dont add the where clause - I dont write a separate query)
Can the same be done inside a sybase store proc and how?
Any reply will be appreciated?
Regards

 
wat u could do is....

DECLARE sqlstring varchar

if(condition)
sqlstring = "select 1"
else(condition)
sqlstring = "select 2"

at the end
exec sqlstring
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top