|
sqlnovice123
Constraint Violating Yak Guru
262 Posts |
Posted - 2010-04-01 : 10:36:37
|
| Hi I am using SQL 2005 and Crystal reports. My final result set from the DB returns NULL value for Maturity for a group of Dealers. I group by Dealers and then by Maturity.For maturity, I call a function called Ytm. which gives month rangeSET ANSI_NULLS OFFGOSET QUOTED_IDENTIFIER OFFGOALTER FUNCTION [dbo].[YtM]( @TradeDate datetime, @Maturity datetime)RETURNS DECIMAL(10,5)ASBEGINDECLARE @Result DECIMAL(10,5)SELECT @Result = CONVERT ( DECIMAL(10,5), DATEDIFF ( dd, @TradeDate, @Maturity ) / 365.00 )RETURN(@Result)ENDFor Maturity, I assign the below using CASE.Maturity = CASE WHEN dbo.YtM(inq.InquiryDate, iss.Maturity) <=1 THEN '<=1 Year' WHEN dbo.YtM(inq.InquiryDate, iss.Maturity) >1 and dbo.YtM(trd.TradeDate, iss.Maturity) <=3 THEN '>1 Year & <=3 Years' WHEN dbo.YtM(inq.InquiryDate, iss.Maturity) >3 and dbo.YtM(trd.TradeDate, iss.Maturity) <=5 THEN '>3 Years & <=5 Years' WHEN dbo.YtM(inq.InquiryDate, iss.Maturity) >5 THEN '>5 Years' ENDIs there a way I can eliminate the NULL values for Maturity using where clause? I tried something like below using a where clause but that gave me no data at all.where dlr.Maturity != NULLSELECT DISTINCT dlr.ProductID AS ProductID, dlr.Product AS Product, SizeBucket, avgdlr.DealerBucket AS Dealer, dlr.Maturity As Maturity, InquiryCount, InquiryVolume, TradeCount, dlr.HitRatioCount AS HitRatioCount, TradeVolume, dlr.HitRatioVolume AS HitRatioVolume, avgdlr.AvgDlrCnt AS AvgDealerCount, avgdlr.AvgRspCntWithLevel AS AvgResponseCount, @ColumnValues AS ProductName, @ClientDesc AS TypeofClient, @ProductDesc As ProductType, @ClientValues AS ClientTypeName from #DealerTemp dlr INNER JOIN #AvgDealerResponse avgdlrON avgdlr.ProductID = dlr.ProductIDgroup by dlr.SizeBucket, dlr.ProductID, dlr.Product, avgdlr.AvgDlrCnt, avgdlr.AvgRspCntWithLevel, avgdlr.DealerBucket, dlr.Maturity, InquiryCount, InquiryVolume, TradeCount, dlr.HitRatioCount, TradeVolume, dlr.HitRatioVolumeorder by dlr.ProductID GOexample of resultsDealer Maturity InquiryCount InquiryVol >=1 & <=5 Dealers NULL 5552 1083683 >=6 & <=10 Dealers NULL 5552 1083683 Thanks for your help |
|