Wednesday, March 7, 2012

Can SQL break an array into one string? [Stored Procedure]

Hello, I have a question on sql stored procedures.
I have such a procedure, which returnes me rows with ID-s.
Then in my asp.net page I make from that Id-s a string like

SELECT * FROM [eai.Documents] WHERECategoryId=11 ORCategoryId=16 ORCategoryId=18.

My question is: Can I do the same in my stored procedure?
Here is it:

set ANSI_NULLSONset QUOTED_IDENTIFIERONgoALTER PROCEDURE [dbo].[eai.GetSubCategoriesById](@.Idint)ASdeclare @.pathvarchar(100);SELECT @.path=PathFROM [eai.FileCategories]WHERE Id = @.Id;SELECT Id, ParentCategoryId,Name, NumActiveAdsFROM [eai.FileCategories]WHERE PathLIKE @.Path +'%'ORDER BY Path

Thank you
Artashes

There is no Array in Stored procedure, but you do can it by use dynamic sql . pass stored procedure a string as 11,16,18

then

in store procedure do

exec N'select * from yourTable where id in ' + @.idlist

Hope this help

|||

DavidDu thank you for answer. I found another solution.

It is herehttp://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=475225&SiteID=1

Artashes

No comments:

Post a Comment