A) After creating the function and calling it in my query, I noticed that it returns both ‘Qualified’ and ‘NULL’ results in the ‘Reports’ column. And this is not good for obvious reasons. Simplifying the logic behind it is what’s driving me nuts. How do I add a clause - where a clause cannot be added? Do I have to alter the function with some conversion, insert the results into a table and then do a function, maybe another variable? What am I missing?
B) My whole argument is, why can I not add a WHERE clause when querying the [dbo].[FactInternetSales] table with the function in the SELECT statement? Should this alteration be made in the function itself to be able to return a result with a WHERE clause? and if so, how do I go about doing just that?
ALTER FUNCTION [dbo].[ExTaxQual]
(@Val1 money
,@Val2 money)
RETURNS char(4) AS
BEGIN
DECLARE @result char(4)
IF (@Val1 + @Val2) > 1000
SET @result = 'Qualified'
ELSE
SET @result = NULL
RETURN
@result
END
And my query:
SELECT
[ExtendedAmount]
,[TaxAmt]
,[dbo].[ExTaxQual]([ExtendedAmount]
,[TaxAmt]) AS 'Reports'
FROM
[dbo].[FactInternetSales]
Result..
SELECT [ExtendedAmount] ,[TaxAmt] ,[dbo].[ExTaxQual]([ExtendedAmount] ,[TaxAmt]) AS 'Reports' FROM [dbo].[FactInternetSales] ------------------------*/
(60398 row(s) affected)
Which is not nearly consistent enough.
B) Maybe the example below is a bit clearer
SELECT [ExtendedAmount]
,[TaxAmt]
,[dbo].[ExTaxQual](
[ExtendedAmount]
,[TaxAmt])
AS Report
FROM [dbo].[FactInternetSales]
WHERE [ExtendedAmount] + [TaxAmt] = 'Qualified'
------------------------------VS
SELECT [ExtendedAmount],
[TaxAmt],
'Qualified' AS Reports
FROM [dbo].[FactInternetSales]
WHERE [ExtendedAmount] + [TaxAmt] > 1000
NULLvalue?