forked from sannlynnhtun-coding/NCTM.POS.App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSP_GenerateSaleInvoiceNo.sql
59 lines (46 loc) · 1.06 KB
/
SP_GenerateSaleInvoiceNo.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
USE [NCTM_POS]
GO
/****** Object: StoredProcedure [dbo].[SP_GenerateSaleInvoiceNo] Script Date: 4/26/2024 12:32:41 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[SP_GenerateSaleInvoiceNo]
-- Add the parameters for the stored procedure here
AS
BEGIN
DECLARE @Sequence INT
,@Code VARCHAR(10)
,@Length INT
,@Fields VARCHAR(50)
,@ReplicateValue VARCHAR(max)
,@InvoiceNo VARCHAR(max)
SET @Fields = 'SaleInvoice'
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT @Sequence = Sequence + 1
,@Code = Code
,@Length = Length
FROM Tbl_Sequence
WHERE Fields = @Fields
PRINT @Sequence
PRINT @Code
PRINT @Length
UPDATE Tbl_Sequence
SET Sequence = @Sequence
WHERE Fields = @Fields
SET @ReplicateValue = (
SELECT REPLICATE('0', @Length - LEN(@Sequence))
);
PRINT @ReplicateValue
SET @InvoiceNo = (
SELECT @Code + CONCAT (
@ReplicateValue
,@Sequence
)
);
PRINT @InvoiceNo
END
GO