Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- declare @input nvarchar(9) = '100d100'
- ;with parse as
- (
- select
- rolls = cast(left(@input,charindex('d',@input)-1) as int)
- ,die = cast(substring(@input,charindex('d',@input)+1,9) as int)
- )
- ,roll as
- (
- select
- n = 1
- ,roll = crypt_gen_random(2)%die+1
- from parse
- union all
- select n+1, crypt_gen_random(2)%die+1
- from roll, parse
- where n+1 < rolls
- )
- ,combine as
- (
- select
- row = 1
- ,result = cast(roll as nvarchar(max))
- from roll
- where n = 1
- union all
- select
- row+1
- ,cast(result + ' ' + cast(roll as nvarchar(max)) as nvarchar(max))
- from combine,roll
- where row = n
- )
- select result
- from combine
- where row = (select max(row) from combine)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement