SQL Server Format SQL table into HTML message (Not HTML table)?

ut6juiuv  于 2023-04-19  发布在  其他
关注(0)|答案(1)|浏览(106)

SQL Table
| Name | Missing |
| ------------ | ------------ |
| B | Jan |
| A | Jan |
| A | Mar |

Desired Result

A is missing Jan, Mar
B is missing Jan

How can I format the above sql table into the desired html? I have experience replicating this into an html table for sending out an email but not much else...

guicsvcw

guicsvcw1#

Just a guess, but here is an option using string_agg()

with cte as (
Select Name,
       Missing = string_agg(missing,', ') 
 From  YourTable 
 Group By Name
)
Select string_agg(concat(Name,' is missing ',Missing),'<br>')
 From  cte

Results

A is missing Jan, Mar<br>B is missing Jan

相关问题