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)
 Select where IN query problem

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 count
WHERE (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 count
WHERE (buyerstatus IN (@customerstatus))
Print @customerstatus

The 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 you
Devon 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
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2003-07-23 : 15:42:06
quote:

Declare @customerstatus char(7)
Set @customerstatus = ('0','#')
SELECT *
FROM count
WHERE (buyerstatus IN (@customerstatus))
Print @customerstatus



Can ANYONE tell me why this is SOOOOOOOOOO popular?

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=25830



Brett

8-)
Go to Top of Page

Arnold Fribble
Yak-finder General

1961 Posts

Posted - 2003-07-23 : 15:54:18
It's some sort of semantic-syntactic mental crosstalk.


Go to Top of Page
   

- Advertisement -