日期:2014-05-17  浏览次数:20628 次

RAISERROR怎么连接字符串
DECLARE 
@RecCount float,@PoCount float,@MCode nvarchar(50)
IF(@PoCount>@RecCount)
BEGIN
  ROLLBACK TRAN
  RAISERROR('物料 %s 累计采购数量 大于累计承认数量  !',18,18,@MCode)
END


我想输出的结果为'物料xxx计采购数量 大于累计承认数量 ,累计采购100pcs,累计承认90pcs'

------解决方案--------------------
DECLARE @RecCount float,@PoCount float,@MCode nvarchar(50), @RecCount2 INT, @PoCount2 INT
SELECT @MCode = 'aa', @RecCount=100,@PoCount=90
SELECT @RecCount2=cast(@RecCount AS int), @PoCount2=cast(@PoCount AS int)
RAISERROR('物料%s计采购数量 大于累计承认数量 ,累计采购%dpcs,累计承认%dpcs',16,1,@MCode,@RecCount2,@PoCount2)
/*
消息 50000,级别 16,状态 1,第 12 行
物料aa计采购数量 大于累计承认数量 ,累计采购100pcs,累计承认90pcs
*/

------解决方案--------------------
DECLARE @RecCount float,@PoCount float,@MCode nvarchar(50),@c nvarchar(max)

--這裡組合提示內容
SET @c='物料xxx计采购数量 大于累计承认数量 ,累计采购100pcs,累计承认90pcs'

IF(@PoCount>@RecCount)
BEGIN
  ROLLBACK TRAN
  RAISERROR(@c,18,18,@MCode)
END