Kıs_FisnoSırala_RowNumber
SELECT FICHENO ,"Seq"=CASE WHEN LEN(ConverT(nvarchar(50),ROW_NUMBER() OVER (ORDER BY DATE_,LOGICALREF)))=1 THEN 'ARV201700000000'+ConverT(nvarchar(50),ROW_NUMBER() OVER (ORDER BY DATE_,LOGICALREF)) WHEN LEN(ConverT(nvarchar(50),ROW_NUMBER() OVER (ORDER BY DATE_,LOGICALREF)))=2 THEN 'ARV20170000000'+ConverT(nvarchar(50),ROW_NUMBER() OVER (ORDER BY DATE_,LOGICALREF)) WHEN LEN(ConverT(nvarchar(50),ROW_NUMBER() OVER (ORDER BY DATE_,LOGICALREF)))=3 THEN 'ARV2017000000'+ConverT(nvarchar(50),ROW_NUMBER() OVER (ORDER BY DATE_,LOGICALREF)) WHEN LEN(ConverT(nvarchar(50),ROW_NUMBER() OVER (ORDER BY DATE_,LOGICALREF)))=4 THEN 'ARV20170000'+ConverT(nvarchar(50),ROW_NUMBER() OVER (ORDER BY DATE_,LOGICALREF)) ELSE '' END FROM dbo.LG_003_03_INVOICE WHERE EINVOICE=2 --------------------------------------------------------------- WITH upd AS ( SELECT FICHENO ,"Seq"=CASE WHEN LEN(ConverT(nvarchar(50),ROW_NUMBER() OVER (ORDER BY DATE_,LOGICALREF)))=1 THEN 'ARV201700000000'+ConverT(nvarchar(50),ROW_NUMBER() OVER (ORDER BY DATE_,LOGICALREF)) WHEN LEN(ConverT(nvarchar(50),ROW_NUMBER() OVER (ORDER BY DATE_,LOGICALREF)))=2 THEN 'ARV20170000000'+ConverT(nvarchar(50),ROW_NUMBER() OVER (ORDER BY DATE_,LOGICALREF)) WHEN LEN(ConverT(nvarchar(50),ROW_NUMBER() OVER (ORDER BY DATE_,LOGICALREF)))=3 THEN 'ARV2017000000'+ConverT(nvarchar(50),ROW_NUMBER() OVER (ORDER BY DATE_,LOGICALREF)) WHEN LEN(ConverT(nvarchar(50),ROW_NUMBER() OVER (ORDER BY DATE_,LOGICALREF)))=4 THEN 'ARV20170000'+ConverT(nvarchar(50),ROW_NUMBER() OVER (ORDER BY DATE_,LOGICALREF)) ELSE '' END FROM dbo.LG_003_03_INVOICE WHERE EINVOICE=2 ) UPDATE upd SET FICHENO = Seq
0 Yorum