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.
| Author |
Topic |
|
devonkyle
Starting Member
19 Posts |
Posted - 2003-07-23 : 15:24:50
|
| I have the following query that works correctly and returns back the desired set of records when coded as follows:SELECT *FROM countWHERE (buyerstatus IN ('0', '#'))But if I recode it like this, which I need to do ,by passing the IN a variable - it no longer works.Declare @customerstatus char(7)Set @customerstatus = ('0','#')SELECT *FROM countWHERE (buyerstatus IN (@customerstatus))Print @customerstatusThe value of @customerstatus is passed via a webform as '0','#' (two values via one webform checkbox/element). I've used SET here to simplify my example of what I'm doing.. The print command returns, as expected, the correct value of '0', '#' - but ZERO records are returned unlike in the first working sample query. DO I need to use some sort of CAST or CONVERT function?Thank youDevon Kyle |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2003-07-23 : 15:30:59
|
| Do a forum search on dynamic sql. You will need to use dynamic sql to accomplish what you are trying to do.Tara |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2003-07-23 : 15:42:06
|
quote: Declare @customerstatus char(7)Set @customerstatus = ('0','#')SELECT *FROM countWHERE (buyerstatus IN (@customerstatus))Print @customerstatus
Can ANYONE tell me why this is SOOOOOOOOOO popular?http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=25830Brett8-) |
 |
|
|
Arnold Fribble
Yak-finder General
1961 Posts |
Posted - 2003-07-23 : 15:54:18
|
| It's some sort of semantic-syntactic mental crosstalk. |
 |
|
|
|
|
|