![sql list of prime numbers sql list of prime numbers](https://derf9v1xhwwx1.cloudfront.net/image/upload/c_fill,q_60,h_630,w_1290/oth/FunimationStoreFront/1327322/English/1327322_English_KeyArt-OfficialVideoImage_c0d413f7-5151-e711-8175-020165574d09.jpg)
Result: 1) Feed cats 2) Water dog 3) Feed garden 4) Paint carpet 5) Clean roof 6) Feed cats We could also use the CONCAT() function to combine two fields together, separated by their own separator.Įxample: SELECT STRING_AGG(CONCAT(TaskId, ') ', TaskName), ' ') It can be separated by any expression of NVARCHAR or VARCHAR type, and it can be a literal or a variable. Of course, it doesn’t necessarily need to be separated by a comma. Result: Feed cats, Water dog, Feed garden, Paint carpet, Clean roof, Feed cats Like this: SELECT STRING_AGG(TaskName, ', ')
![sql list of prime numbers sql list of prime numbers](https://www.kodyaz.com/images/python/python-program-code-prime-number-checker.png)
So we could take the above data, and use the STRING_AGG() function to list all the task names in one big comma separated list. This article provides examples that demonstrate the T-SQL STRING_AGG() function.įirst, here’s some sample data.
![sql list of prime numbers sql list of prime numbers](https://www.tutorialgateway.org/wp-content/uploads/Python-Program-to-find-Prime-Number-1.png)
This works in much the same way to MySQL’s GROUP_CONCAT() function. Transact-SQL now has the STRING_AGG() function, which concatenates the values of string expressions and places separator values between them. While it’s true that you could achieve this same effect prior to SQL Server 2017, it was a bit fiddly. This means you can have your result set appear as a comma-separated list, a space-separated list, or whatever separator you choose to use. Starting with SQL Server 2017, you can now make your query results appear as a list.