I have a table with 2 columns:
select product, quantity from datainformation
this table returns:
product quantity
1 10
2 30
4 23
191 10
900 1
1234 5
12345 2
- two columns are int.
- table could to have N records
I need to get 2 Strings for EVERY 50 records. My question is how to get these strings:
stringproducts='1 2 4 191 900 1234 12345'
stringquantity='10 30 23 10 1 5 2 '
Now I need these strings for every 50 records so, for example, if I have 51 records I need
my second “block” to have the last product and the last quantity.
In another language I could use ltrim(cad,5). How would I do this in SQL?
Can I use stuff for this? Or do I need a loop and concatenate them 1 for 1?
I believe with a stuff it could be easier (maybe a stuff inside a loop but it would be easier a loop for every record)
You can use
FOR XML PATHandSTUFF():See SQL Fiddle with Demo