我有這樣
中值的N個NUM
一個表有這樣我怎麼能找到失蹤相同的格式ExciseInvoiceNo
,鑑於我怎麼能從表中找到缺失值?
DECLARE @temp table
(val int)
insert INTO @temp([val])
SELECT CONVERT(INT, (case when CHARINDEX('/', EXCISEINVOICENO) > 0 Then
cast(substring(EXCISEINVOICENO,1,len(EXCISEINVOICENO) - 3) as int)
else Cast(EXCISEINVOICENO as Int) end) ) as ExciseInvoiceIndex
FROM tblExciseInvoice
WHERE CompYearID=109
AND (InvoiceDate BETWEEN '10/1/2015 12:00:00 AM' AND '03/30/2016 11:59:59 PM')
select (select isnull(max(val)+1,1) from @temp where val < md.val) as [from],
md.val - 1 as [to]
from @temp md
where md.val != 1 and not exists (
select 1 from @temp md2 where md2.val = md.val - 1)
我試圖這一點,但在適當的沒有得到結果Formate
請編輯我們的問題,並提供樣品數據和預期結果。正如所寫的,你的問題太模棱兩可了。 –
附上樣品桌請點擊圖片 – Ritesh
您可以使用[此工具](https://ozh.github.io/ascii-tables/)創建漂亮的桌子。 – robsn