Float in RaiseError

how to display the variable of float type in Raiserror statement in sqlsver,
see my below code.

--in below select state, i have added only fQtyLastProcess
                  Select @cLotNo = cLotNumber,@fQtyLastProcess = fQtyLastProcess From _btblInvoiceLines
                  Where iInvoiceID in ( Select AutoIndex From Inserted Where DocFlag <> 2)
--Add by Ramzan following block is added
                  SELECT    @fQtyExisting= isnull(sum(dbo._etblLotTrackingQty.fQtyOnHand),0) FROM dbo._etblLotTracking INNER JOIN
            dbo._etblLotTrackingQty ON dbo._etblLotTracking.idLotTracking = dbo._etblLotTrackingQty.iLotTrackingID
                  WHERE     (dbo._etblLotTracking.cLotDescription <> 'OPENING') AND (dbo._etblLotTrackingQty.fQtyOnHand <> 0) and cLotDescription = @cLotNo
                  if ((@fQtyLastProcess + @fQtyExisting)>30)
                  Begin
                        raiserror('Qty Cannot be More than 30MT. in %d',16,1,Convert(VARCHAR(10), @fQtyLastProcess))
                  end
--end by Ramzan
my raiserror statement is giving error.
mahmood66Asked:
Who is Participating?
 
halfbloodprinceConnect With a Mentor Commented:
Try this:
Declare @ErrorMsg Varchar(Max)
Set @ErrorMsg = ''Qty Cannot be More than 30MT ' + Cast(@fQtyLastProcess as Varchar(20))
   if ((@fQtyLastProcess + @fQtyExisting)>30)
                  Begin
                        raiserror(@ErrorMsg,16,1)
                  end
0
 
dshrivallabhCommented:
Write RAISERROR('Qty Cannot be More than 30MT. in ' + CONVERT(VARCHAR(10),CONVERT(numeric(16,3),@fQtyLastProcess)))
0
 
Shannon_LowderCommented:
I hate to be the bearer of bad news, but floats cannot be used for the Argument parameter.  Only tinyint, smallint, int, char, varchar, nchar, nvarchar, binary, or varbinary can be used.  But I think you might be able to try this workaround:

---
Shannon Lowder
Database Engineer
http://toyboxcreations.net
--try this:
DECLARE @varchar_fQtyLastProcess VARCHAR(10)
SET @varchar_fQtyLastProcess = CONVERT(VARCHAR(10), @fQtyLastProcess)
RAISERROR('Qty Cannot be More than 30MT. in %s',16,1,@varchar_fQtyLastProcess)

---in place of 
 raiserror('Qty Cannot be More than 30MT. in %d',16,1,Convert(VARCHAR(10), @fQtyLastProcess))

Open in new window

0
All Courses

From novice to tech pro — start learning today.