我想算在我的表中的記錄,使我創造回報1.下面的函數數字是多少我有:計數的SQL函數返回值
CREATE FUNCTION isErrorMismatch
(@theType nvarchar(1), @theExCode nvarchar(2))
RETURNS bit
AS
BEGIN
DECLARE @theTypeAsInt int
SET @theTypeAsInt = CAST(@theExCode AS INT)
DECLARE @returnValue bit
SET @returnValue = 0
IF @theType = 'A'
IF @theTypeAsInt >= 10 AND @theTypeAsInt <= 17
SET @returnValue = 0
ELSE
SET @returnValue = 1
ELSE IF @theType = 'B'
IF @theTypeAsInt >= 18 AND @theTypeAsInt <= 26
SET @returnValue = 0
ELSE
SET @returnValue = 1
ELSE IF @theType = 'C'
IF @theTypeAsInt >= 30 AND @theTypeAsInt <= 38
SET @returnValue = 0
ELSE
SET @returnValue = 1
ELSE
SET @returnValue = 1
RETURN @returnValue
END
GO
SELECT (SELECT COUNT(*)
FROM isErrorMismatch(LEFT(Type, 1),LEFT([Exception Code/Category],2))
As MismatchCount
FROM dbo.[All Service Ticket Data 2012_final]
的每個記錄,使函數返回1,我想要數。當我調用函數時,我的FROM中出現語法錯誤。有人有主意嗎?謝謝!
***更新:
爲了獲得使函數返回1計:
SELECT COUNT(dbo.isErrorMismatch(LEFT(Type, 1), LEFT([Exception Code/Category],2))) As MismatchCount
FROM dbo.[All Service Ticket Data 2012_final]
WHERE dbo.isErrorMismatch(LEFT(Type, 1), LEFT([Exception Code/Category],2)) = 1
爲了得到這一切使函數返回1的記錄:
SELECT Type, [Exception Code/Category],
dbo.isErrorMismatch(LEFT(Type, 1),LEFT([Exception Code/Category] ,2)) as Mismatch
FROM dbo.[All Service Ticket Data 2012_final]
WHERE dbo.isErrorMismatch(LEFT(Type, 1),LEFT([Exception Code/Category] ,2)) = 1
有也顯示,使該函數返回1的記錄的方式?而不是隻顯示計數?謝謝! – KateMak