Link to home
Start Free TrialLog in
Avatar of 4Learning
4Learning

asked on

Dynamic where clause

Can someone show how to create a dynamic where clause in Sybase?

Eg.
I have a select statement with a where clause.

But  based on the count of rows returned from a table I want to add one more condition....
if the count is 0 then no additional condition needs to be added to the where clause
and if the count > 1, then I want to add the values returned by another select query  in the where clause  condition.

Thanks.
Avatar of Jan Franek
Jan Franek
Flag of Czechia image

You can dynamicaly create your select command, store it into varchar variable and then execute it using dynamic exec - see http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.help.ase_15.0.commands/html/commands/commands56.htm
ASKER CERTIFIED SOLUTION
Avatar of Rajesh_Anandappan
Rajesh_Anandappan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 4Learning
4Learning

ASKER

Thankyou for the example. I tried the variable for the select clause, the from clause and the where clause and added them all up in one string and then passed that string as a parameter to the exec command as you listed above.

Thanks.