When you think ASP, think...
logo
spgif
search
spgif
site-index
spgif
Recent Articles xml
All Articles
ASP.NET Articles
ASPFAQs.com
Related Web Technologies
User Tips!
Coding Tips
spgif
spgif spgif
spgif

leftnav-resources
spgif
Sections:
Sample Chapters
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Security
Stump the SQL Guru!
XML Info
Information:
Feedback
Author an Article
spgif
spgif spgif
ASP ASP.NET ASP FAQs Feedback topnav-right
right-bg
Print this page.
The SQL Guru Answers your Questions...


Today's question comes from Eric L.:

I have a question for you. I have been working on this one for a very long time and still have no answers. I have a comma delimited string that I wish to a SQL Server 7.0 Stored Procedure, ex. '1,2,3,4'. I wish to then use this within the where clause like, select * from table where idno in (@stringpassed). I have not been able to get this to work with any methods that I have tried. Can this be done?

Eric,

Yep, you can use the EXEC command to do this. In addition to prefixing stored procedure calls, this command can be used to execute a SQL statement in a string or a string variable. I've included a sample stored proc below...

CREATE PROC Foo
  @stringpassed
AS
BEGIN
  DECLARE @SQL varchar(100)
  SET @SQL = 'SELECT * FROM table WHERE idno IN ' + @stringpassed

  EXEC(@SQL)
END

You can find more information in SQL Server books online.

Sean


Read Other SQL Guru Questions


ASP.NET [1.x] [2.0] | ASPFAQs.com | Advertise | Feedback | Author an Article