Create
table
T1
(Id
int
identity
primary
key
,
VoucherNo
varchar
(4),
TransNo
(10)
)
Insert
into
values
(
'V100'
'Trns1'
),(
'V101'
'V102'
'V103'
'V104'
'V106'
;
WITH
cte
AS
SELECT
*
CAST
SUBSTRING
(VoucherNo, 2, 3)
INT
) - ROW_NUMBER() OVER (
ORDER
BY
Grp
FROM
min
(VoucherNo)
FirstVoucherNo
max
LastVoucherNo
count
(*)
Quantity
GROUP
,Grp
Naomi N edited Revision 14. Comment: Added See Also
Naomi N edited Revision 5. Comment: Minor edit
Naomi N edited Revision 4. Comment: Minor edit
Naomi N edited Revision 3. Comment: Minor grammar corrections
Naomi N edited Revision 2. Comment: Minor grammar corrections
Naomi N edited Revision 1. Comment: Title case
Naomi N edited Original. Comment: Links
Congratulations on winning the gold medal! blogs.technet.com/.../technet-guru-awards-july-2013.aspx
Naomi, your article was featured on MSDN blogs here: blogs.msdn.com/.../transact-sql-guru-gaps-and-islands-problem.aspx
Thank you for all your TechNet Guru contributions!
It was also featured on the Wiki Ninjas blog: blogs.technet.com/.../july-t-sql-guru-naomi-n-wins-again-with-quot-gaps-and-islands-problem-quot.aspx
Congrats on being featured on the home page of TechNet Wiki!
Thanks
Y3T7BWJD55WC