CREATE PROC [dbo].[sp_GetNextSequenceQuote]
(
	@serviceDate DATETIME
	,@surfaceItemId INT
)
AS

DECLARE @sequence INT = 0

SELECT	@sequence = IsNull(Max(sequence), 0) + 1
FROM	pal_Sales A
WHERE	surfaceItemId = @surfaceItemId
		AND dateOfService = @serviceDate
		AND isVisible = 1
		AND itemType = 'QT'

SELECT	@sequence AS SeqNo