If I have understood your question correctly you need a recursive CTE CREATE PROCEDURE dbo. Foo @id int AS WITH divisions AS ( SELECT id, sub_id, name FROM YourTable WHERE id = @id UNION ALL SELECT y. Id, y.
Sub_id, y. Name FROM YourTable y JOIN divisions d ON d. Id = y.
Sub_id ) SELECT id, sub_id, name FROM divisions.
If I have understood your question correctly you need a recursive CTE. CREATE PROCEDURE dbo. Foo @id int AS WITH divisions AS ( SELECT id, sub_id, name FROM YourTable WHERE id = @id UNION ALL SELECT y.Id, y.
Sub_id, y. Name FROM YourTable y JOIN divisions d ON d.Id = y. Sub_id ) SELECT id, sub_id, name FROM divisions.
Yes im need a recursive CTE – 0dd_b1t Oct 22 '10 at 12:50 you have a little mistake - "JOIN divisions d ON d. Id = y. Sub_id" change this and I will mark your answer as accepted =) – 0dd_b1t Oct 22 '10 at 13:08 @0dd_b1t - Ah I often mess that up when I haven't got the data to test against!Done.
– Martin Smith Oct 22 '10 at 13:10.
SELECT id FROM table WHERE sub_id = @target UNION ALL SELECT @target.
Thank you but im need recursive query – 0dd_b1t Oct 22 '10 at 12:45 @0dd_b1t: Seems that @Martin's answer is what you're looking for – abatishchev Oct 22 '10 at 12:56.
Sorry for this maybe foolish question but i'm newbie to SQL Server. I need to create a simply procedure which return me all id of subdivisions in some division (with top division id too). I think I need array with subid's in loop, but I don't know how to create array in SQL Serve o_0 (omg.. array exist in (T)SQL language?
Or maybe another way to get it?
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.