Reddit gives you the best of the internet in one place. Get a constantly updating feed of breaking news, fun stories, pics, memes, and videos just for you. Passionate about something niche? Reddit has thousands of vibrant communities with people that share your interests. Alternatively, find out what’s trending across all of Reddit on r/popular.
![Sql Sql](/uploads/1/2/5/5/125502986/622215209.jpg)
Insert into@basetable select1012,3then the same solution works. I'm trying to avoid dynamic SQL though.The SomeItemIDs are unique within a position (i.e.
No dupes), but not necessarily unique across positions, however for the purpose of this, it shouldn't matter, and you can assume that they are unique.Note also that the ComboId value is unimportant, it's just a unique id that identifies each combo.SolutionIn essence, I use a recursive CTE to generate the combinations as a delimited string - this then copes with the dynamic nature of adding positions. AnotherCTE over this one gives me a unique ComboID.As the items are added in the right order, I can then split the string, using the positions in the string as the original PositionIds.This solution is using Oleg Netchaev's inline string splitting solution (as posted here:).
![Sacar Sacar](/uploads/1/2/5/5/125502986/182988984.jpg)
But for performance I could use aUDF, I just wanted a tidy, encapsulated solution.
Insert into@basetable select1012,3then the same solution works. I'm trying to avoid dynamic SQL though.The SomeItemIDs are unique within a position (i.e.
No dupes), but not necessarily unique across positions, however for the purpose of this, it shouldn't matter, and you can assume that they are unique.Note also that the ComboId value is unimportant, it's just a unique id that identifies each combo.SolutionIn essence, I use a recursive CTE to generate the combinations as a delimited string - this then copes with the dynamic nature of adding positions. AnotherCTE over this one gives me a unique ComboID.As the items are added in the right order, I can then split the string, using the positions in the string as the original PositionIds.This solution is using Oleg Netchaev's inline string splitting solution (as posted here:). But for performance I could use aUDF, I just wanted a tidy, encapsulated solution.