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)
 Declair a full where clause

Author  Topic 

albertkohl
Aged Yak Warrior

740 Posts

Posted - 2007-04-08 : 16:50:29
Okay, so i'm writing a program where a user can input "Selects" on what data they are looking for, and the server returns a value of we have XX many.

i've ran into a bit of a wall, the whole time i've basically planned on coding this so that every select the user adds, gets tacked on the back of whatever select there is. so as the user goes though the selection process, the program builds a query.

well then when i pass the query to the sqlserver, via ASP.net. it wont work. it looks as though you can only use variables in SQL for certain parts of a query, is that correct?

maybe reading the code will give you a better idea of what i was trying to accomplish

working code:

DECLARE @querycode VARCHAR(30)
SET @querycode ='RI'

SELECT state_abbrv, COUNT(state_abbrv) AS Kount
FROM Results
WHERE state_abbrv=@querycode
group by state_abbrv
order by state_abbrv



code i was trying to use:

DECLARE @querycode VARCHAR(30)
SET @querycode =" (RTRIM(county_name) + ', ' + state_abbrv) IN ('KENT, RI')"

SELECT state_abbrv, COUNT(state_abbrv) AS Kount
FROM Results
WHERE @querycode


ANY help would be OUT STANDING!

P.S. the error i get: An expression of non-boolean type specified in a context where a condition is expected, near '@querycode'.

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2007-04-08 : 18:05:59
give this a read: http://www.sommarskog.se/dyn-search.html



www.elsasoft.org
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-04-10 : 06:52:57
Aslo, if you dont pass object name as parameters, avoid dynamic sql

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

albertkohl
Aged Yak Warrior

740 Posts

Posted - 2007-04-10 : 14:48:42
that works great, however i have one issue, how do i incorporate IN commands as parameters ex:

exec order @citylist=''phonenix','flagstaff'' wont work.
i also tried: exec order @citylist="('phonenix','flagstaff')" no dice.

any ideas?
Go to Top of Page
   

- Advertisement -