'T-SQL - How to use results of a query to select multiple rows based on a count

Considering the below example Person table, I am looking for a way to return multiple rows based on an X value. So, if the BagsOut count is, say 3, I would want 3 copies of the row returned or if it was 2 then 2 copies should be returned, and so on:

ID      Name      BagsOut
1       Ken       1
2       Dave      3
3       Ben       2

Desired result:

ID      Name      BagsOut
1       Ken       1
2       Dave      3
2       Dave      3
2       Dave      3
3       Ben       2
3       Ben       2

Is it possible to write this into a single query? I am using T-SQL.

Many thanks in advance for looking.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source