Looking for some help in converting this to a function that I can call from another procedure.
OrderException table contains exception codes for each order and there may be none, one, or more than one exception.
Obviously this code performs 2 selects.
Is there anyway to only do this with only one select?
What would be really nice if it could return the @ExceptStr as well as a comma delimited string of all of the exceptions.
But maybe a future project.
Auguy
Sylvania/Toledo Ohio
OrderException table contains exception codes for each order and there may be none, one, or more than one exception.
Obviously this code performs 2 selects.
Is there anyway to only do this with only one select?
What would be really nice if it could return the @ExceptStr as well as a comma delimited string of all of the exceptions.
But maybe a future project.
Code:
DECLARE @ExceptStr varchar(15)
DECLARE @RowCnt int
SELECT ExceptionID from OrderException
SET @RowCnt = @@ROWCOUNT
If @RowCnt = 0 SET @ExceptStr = 'NONE'
If @RowCnt = 1 SET @ExceptStr = (SELECT TOP 1 ExceptionID FROM OrderException ORDER BY ExceptionID)
If @RowCnt > 1 SET @ExceptStr = '** MULTIPLE **'
SELECT @ExceptStr
Auguy
Sylvania/Toledo Ohio