Select * from Master_Reference_Running
WHERE RYear = year(getdate()) and RMonth = month(getdate()) and RDay = day(getdate())
RETURN
GO
----------------------------------------------------------------------------------------------------
CREATE PROCEDURE sp_GetRunnoRefNo
AS
SELECT RYear, RMonth, RDay, Running from Master_Reference_Running
WHERE RYear = year(getdate()) and RMonth = month(getdate()) and RDay = day(getdate())
RETURN
GO
Code (VB.NET)
Public Function GenRefNo() As String
Dim result As Boolean = False
Dim dtResult As DataTable
Dim refno As String = ""
Try
dtInvoice = New DataTable()
dtInvoice = ExecuteStore("sp_getRunnoRefNo")
If dtInvoice.Rows.Count = 0 Then
dtResult = New DataTable()
dtResult = ExecuteStore("sp_InsertRunnoRefNo")
If dtResult.Rows.Count = 1 Then
refno = dtResult.Rows(0)("RYear").ToString() + Integer.Parse(dtResult.Rows(0)("RMonth").ToString().Trim()).ToString("#00") + Integer.Parse(dtResult.Rows(0)("RDay").ToString().Trim()).ToString("#00") + (Integer.Parse(dtResult.Rows(0)("Running").ToString()) + 1).ToString("#0000")
End If
Else
refno = dtInvoice.Rows(0)("RYear").ToString() + Integer.Parse(dtInvoice.Rows(0)("RMonth").ToString().Trim()).ToString("#00") + Integer.Parse(dtInvoice.Rows(0)("RDay").ToString().Trim()).ToString("#00") + (Integer.Parse(dtInvoice.Rows(0)("Running").ToString()) + 1).ToString("#0000")
End If
Catch ex As Exception
Throw ex
End Try
Return refno
End Function