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
 Transact-SQL (2000)
 WHERE Ident IN ( @ListofIdents ) : stumped!

Author  Topic 

vitc
Starting Member

3 Posts

Posted - 2006-02-12 : 18:12:55
I am creating a sql function that will use a cursor to generate a list of email addresses based on a supplied list of table identities. This is returned in a query to coldfusion. Problem is the @ListofIdents in the function has to be varchar datatype and the identities are numeric. So I don't know how to do this:

WHERE Ident IN ( @ListofIdents )

for example:
WHERE Ident IN ( 180,181,190 )

Been a long day so I maybe missing the obvious! Help!!

Thanks.

nr
SQLTeam MVY

12543 Posts

Posted - 2006-02-12 : 18:29:31
where ',' + @ListofIdents + ',' like '%,' + convert(varchar(20),Ident) + ',%'

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

vitc
Starting Member

3 Posts

Posted - 2006-02-12 : 18:39:06
YOU ROCK!!!

Thanks so much - one quick question ( though it won't be an issue for my problem, but for future knowledge).

What would happend by chance with this list:

18,20

And the database had these identities:

18,20,180,200

Would it return the emails of ident 18,20 AND 180,200?? Since the LIKE statment.

Again thanks...
Go to Top of Page

vitc
Starting Member

3 Posts

Posted - 2006-02-12 : 18:48:22
Ok, worked out the logic on paper and I think the answer to my question is no. Cool...
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2006-02-12 : 19:10:35
See
http://www.nigelrivett.net/SQLTsql/InCsvStringParameter.html

It's why it needs the extra ","'s in the statement

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2006-02-12 : 19:17:57
If you are going to use dynamic SQL, you could just do this:

exec ( 'select * from Mytable WHERE Ident IN ('+@ListofIdents+')' )



CODO ERGO SUM
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-02-13 : 02:18:56
Also search for where in @MYCSV here
http://sqlteam.com/forums/topic.asp?TOPIC_ID=55210

Madhivanan

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

- Advertisement -