Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 SQL Server-Dynamic Query

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-12-03 : 08:00:41
Hemali Desai writes "I have one table PScriteria which contains criteria fields
contains value like
1.amt between 10000 and 20000
2.AND (type=educational or type = research)
3.
4.

now In my query,In where clause I want single logical ecpression made of all criteria available in PSCriteria table

Like
select count(*) from table
where
(amt between 10000 and 20000
AND (type=educational or type = research)....)"

Andraax
Aged Yak Warrior

790 Posts

Posted - 2004-12-03 : 08:18:33
Hi!

Use dynamic SQL. Declare a varchar variable and fill it with your statement. Then use exec () or sp_executesql to run it. You can look up sp_executesql in BOL for more information.

/Andraax
Go to Top of Page

Frank Kalis
Constraint Violating Yak Guru

413 Posts

Posted - 2004-12-03 : 10:04:17
Read this http://www.sommarskog.se/dynamic_sql.html and http://www.sommarskog.se/dyn-search.html and decide for yourself if you're going down that road.

--Frank
http://www.insidesql.de
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2004-12-03 : 11:04:10
Can you be more detailed as you what you are trying to do, what the end result is? from your description, it sounds like you are just storing a single WHERE clause, broken out into a table. Why do you feel you need to do this?

- Jeff
Go to Top of Page
   

- Advertisement -