`DECLARE @MYACCOUNT CHAR(2),
@REPORTTYPE CHAR(1),
@BRANCHCODE CHAR(3)
SELECT @MYACCOUNT='SV',
@REPORTTYPE='D',
@BRANCHCODE='001'
IF NOT EXISTS(SELECT 1 FROM TBL_Category WHERE CategoryType=@MYACCOUNT)
SELECT 'INVALID ACCOUNT NAME IS : '+@MYACCOUNT
ELSE IF NOT EXISTS(SELECT 1 FROM TBL_Category WHERE CatGroup=@REPORTTYPE)
SELECT 'INVALID REPORT NAME IS : '+@REPORTTYPE
ELSE IF NOT EXISTS(SELECT 1 FROM BranchMaster WHERE MBranchCode=@BRANCHCODE)
SELECT 'INVALID BRANCH CODE IS : '+@BRANCHCODE
ELSE
SELECT M.MBranchCode, SUM(M.MMiscBaln) FROM MasterTable M, TBL_Category T
WHERE T.CategoryCode=M.MAcType
AND T.CategoryType=@MYACCOUNT
AND T.CatGroup=@REPORTTYPE
AND M.MBranchCode=@BRANCHCODE
GROUP BY M.MBranchCode`
我想要一个解决方案,当我在变量中输入错误的数据时,它应该抛出错误消息。可能有多个错误,但应显示这些变量的错误。例如:
如果我输入值:
`@BRANCHCODE='002'
@REPORTTYPE='A'
@MYACCOUNT='SQ'`
@BRANCHCODE 是正确的。然后它应该抛出@REPORTTYPE 和@MYACCOUNT 是错误的消息。