Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

66%
+2 −0
Q&A How to break infinite loop in CTE

Estela's answer provides great insight about how to do it also in SQL Server. Unfortunately, there does not seem to be a build-in array functionality, so one way is to rely on strings as shown here...

posted 3y ago by Alexei‭  ·  last activity 3y ago by Alexei‭

Answer
#7: Post undeleted by user avatar Alexei‭ · 2021-04-20T15:49:31Z (over 3 years ago)
#6: Post edited by user avatar Alexei‭ · 2021-04-20T15:41:46Z (over 3 years ago)
  • Estela's answer provides great insight about how to do it also in SQL Server. Unfortunately, there does not seem to be a build-in array functionality, so one way is to rely on strings as shown [here](https://dba.stackexchange.com/q/162298).
  • Basically, instead of accumulating values in an array, a string does this (way less efficiently for many records, I would say).
  • In this case, a query that seems to provide the results you are looking for is the following:
  • **Note:** considering how complex things might get (edge cases might add up to the logic), this type of query might be better be done in a language/framework like C++, Java or .NET, unless there is a very strong reason to remain in SQL. These allow for much more flexibility, considering the iterative nature of the algorithm (not so suitable for set based operations) and also provide way better-debugging capabilities.
  • Estela's answer provides great insight about how to do it also in SQL Server. Unfortunately, there does not seem to be a build-in array functionality, so one way is to rely on strings as shown [here](https://dba.stackexchange.com/q/162298).
  • Basically, instead of accumulating values in an array, a string does this (way less efficiently for many records, I would say).
  • In this case, a query that seems to provide the results you are looking for is the following (some security check does not allow to post the query, so I am using SQL fiddle for sharing it):
  • http://sqlfiddle.com/#!18/a50101/1
  • **Note:** considering how complex things might get (edge cases might add up to the logic), this type of query might be better be done in a language/framework like C++, Java or .NET, unless there is a very strong reason to remain in SQL. These allow for much more flexibility, considering the iterative nature of the algorithm (not so suitable for set based operations) and also provide way better-debugging capabilities.
#5: Post edited by user avatar Alexei‭ · 2021-04-20T15:34:37Z (over 3 years ago)
  • Estela's answer provides great insight about how to do it also in SQL Server. Unfortunately, there does not seem to be a build-in array functionality, so one way is to rely on strings as shown [here](https://dba.stackexchange.com/q/162298).
  • Basically, instead of accumulating values in an array, a string does this (way less efficiently for many records, I would say).
  • In this case, a query that seems to provide the results you are looking for is the following:
  • Estela's answer provides great insight about how to do it also in SQL Server. Unfortunately, there does not seem to be a build-in array functionality, so one way is to rely on strings as shown [here](https://dba.stackexchange.com/q/162298).
  • Basically, instead of accumulating values in an array, a string does this (way less efficiently for many records, I would say).
  • In this case, a query that seems to provide the results you are looking for is the following:
  • **Note:** considering how complex things might get (edge cases might add up to the logic), this type of query might be better be done in a language/framework like C++, Java or .NET, unless there is a very strong reason to remain in SQL. These allow for much more flexibility, considering the iterative nature of the algorithm (not so suitable for set based operations) and also provide way better-debugging capabilities.
#4: Post deleted by user avatar Alexei‭ · 2021-04-20T15:33:13Z (over 3 years ago)
#3: Post edited by user avatar Alexei‭ · 2021-04-20T15:31:02Z (over 3 years ago)
  • Estela's answer provides great insight about how to do it also in SQL Server. Unfortunately, there does not seem to be a build-in array functionality, so one way is to rely on strings as shown [here](https://dba.stackexchange.com/q/162298).
  • Estela's answer provides great insight about how to do it also in SQL Server. Unfortunately, there does not seem to be a build-in array functionality, so one way is to rely on strings as shown [here](https://dba.stackexchange.com/q/162298).
  • Basically, instead of accumulating values in an array, a string does this (way less efficiently for many records, I would say).
  • In this case, a query that seems to provide the results you are looking for is the following:
#2: Post edited by user avatar Alexei‭ · 2021-04-20T15:30:34Z (over 3 years ago)
  • test
  • Estela's answer provides great insight about how to do it also in SQL Server. Unfortunately, there does not seem to be a build-in array functionality, so one way is to rely on strings as shown [here](https://dba.stackexchange.com/q/162298).
#1: Initial revision by user avatar Alexei‭ · 2021-04-20T15:30:22Z (over 3 years ago)
test