SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


ISNull Not working


ISNull Not working

Author
Message
Faye Fouladi
Faye Fouladi
SSC Eights!
SSC Eights! (970 reputation)SSC Eights! (970 reputation)SSC Eights! (970 reputation)SSC Eights! (970 reputation)SSC Eights! (970 reputation)SSC Eights! (970 reputation)SSC Eights! (970 reputation)SSC Eights! (970 reputation)

Group: General Forum Members
Points: 970 Visits: 187
SELECT OrgCode AS UnitState , OrgCode As State, IsNull(Count(*), 0) As [SLRP Approved]
FROM tLookup_StateTable LKState Left Join dbo.tbl_Status_Of_ContractRequests_By_State TBL on LKState.OrgCode = TBL.UnitState Inner Join
dbo.tblContracts C ON C.Contract_ID = TBL.TrackingID
LEFT OUTER JOIN dbo.tLookup_Incentive Lkp ON C.IT_CODE = Lkp.IT_ID

Where (TBL.APPROVED > 0) AND (TBL.VERIFIED = 0) AND (TBL.[VERIFICATION FAILED] = 0) AND (TBL.[SYS VERIF - LOSS] = 0) AND (C.ContractStatus = 'A') AND C.IT_Code = 'S'
Group By OrgCode


I expect the above code to list all the states and when the count for a particular state is null replace it with zero, but this is not working
amfrizzell
amfrizzell
SSC Rookie
SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)

Group: General Forum Members
Points: 40 Visits: 117
Just for giggles, try using the caolescle(ltlrim(rtrim(value)), 0) instead of isnull(value, 0)

That might work in this case..

Aaron
ChrisM@Work
ChrisM@Work
SSC Guru
SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)

Group: General Forum Members
Points: 65912 Visits: 20214
Not much information to go on.
Run the following code and post back comments.

SELECT 
OrgCode AS UnitState ,
OrgCode As State,
COUNT(*) AS Rows_Per_OrgCode
--IsNull(Count(*), 0) As [SLRP Approved]
FROM tLookup_StateTable LKState
Left Join dbo.tbl_Status_Of_ContractRequests_By_State TBL on LKState.OrgCode = TBL.UnitState
Inner Join dbo.tblContracts C ON C.Contract_ID = TBL.TrackingID
LEFT OUTER JOIN dbo.tLookup_Incentive Lkp ON C.IT_CODE = Lkp.IT_ID

Where (TBL.APPROVED > 0) AND (TBL.VERIFIED = 0) AND (TBL.[VERIFICATION FAILED] = 0) AND (TBL.[SYS VERIF - LOSS] = 0)
AND (C.ContractStatus = 'A') AND C.IT_Code = 'S'

Group By OrgCode



“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
ALZDBA
ALZDBA
SSC-Forever
SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)

Group: General Forum Members
Points: 47891 Visits: 9075
There is an Inner join with a outer joined object, so the inner join on NULL may be your issue .

Inner Join dbo.tblContracts C
ON C.Contract_ID = TBL.TrackingID



So, this may be avoided by altering the inner join to another left join
or maybe better a nested inner join, by shifting the left joined on clause like this.

SELECT  OrgCode AS UnitState
, OrgCode As State
, IsNull(Count(*), 0) As [SLRP Approved]
FROM tLookup_StateTable LKState
Left Join dbo.tbl_Status_Of_ContractRequests_By_State TBL
on LKState.OrgCode = TBL.UnitState
LEFT Join dbo.tblContracts C ------ altered inner to left join (consequences)
ON C.Contract_ID = TBL.TrackingID
LEFT OUTER JOIN dbo.tLookup_Incentive Lkp
ON C.IT_CODE = Lkp.IT_ID
Where ( TBL.APPROVED > 0 )
AND ( TBL.VERIFIED = 0 )
AND ( TBL.[VERIFICATION FAILED] = 0 )
AND ( TBL.[SYS VERIF - LOSS] = 0 )
AND ( C.ContractStatus = 'A' )
AND C.IT_Code = 'S'
Group By OrgCode



SELECT OrgCode AS UnitState
, OrgCode As State
, IsNull(Count(*), 0) As [SLRP Approved]
FROM tLookup_StateTable LKState
Left Join dbo.tbl_Status_Of_ContractRequests_By_State TBL
Inner Join dbo.tblContracts C
ON C.Contract_ID = TBL.TrackingID
on LKState.OrgCode = TBL.UnitState --- nested inner join with left join
LEFT OUTER JOIN dbo.tLookup_Incentive Lkp
ON C.IT_CODE = Lkp.IT_ID
Where ( TBL.APPROVED > 0 )
AND ( TBL.VERIFIED = 0 )
AND ( TBL.[VERIFICATION FAILED] = 0 )
AND ( TBL.[SYS VERIF - LOSS] = 0 )
AND ( C.ContractStatus = 'A' )
AND C.IT_Code = 'S'
Group By OrgCode



Please test it and let us know your findings !

Johan


Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere w00t

- How to post Performance Problems
- How to post data/code to get the best help


- How to prevent a sore throat after hours of presenting ppt ?


press F1 for solution, press shift+F1 for urgent solution :-D


Need a bit of Powershell? How about this

Who am I ? Sometimes this is me Alien but most of the time this is me Hehe
Faye Fouladi
Faye Fouladi
SSC Eights!
SSC Eights! (970 reputation)SSC Eights! (970 reputation)SSC Eights! (970 reputation)SSC Eights! (970 reputation)SSC Eights! (970 reputation)SSC Eights! (970 reputation)SSC Eights! (970 reputation)SSC Eights! (970 reputation)

Group: General Forum Members
Points: 970 Visits: 187
this problem was posted long time ago. I no longer work on this project, therefore, I cannot test it.
Jason Selburg
Jason Selburg
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10151 Visits: 4131
Faye Fouladi (7/21/2011)
this problem was posted long time ago. I no longer work on this project, therefore, I cannot test it.


You mean you don't work on the same issue for a year and a half? Hehe

______________________________________________________________________

Personal Motto: Why push the envelope when you can just open it?

If you follow the direction given HERE you'll likely increase the number and quality of responses you get to your question.

Jason L. Selburg
ALZDBA
ALZDBA
SSC-Forever
SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)

Group: General Forum Members
Points: 47891 Visits: 9075
Faye Fouladi (7/21/2011)
this problem was posted long time ago. I no longer work on this project, therefore, I cannot test it.


Oops, I didn't see the original date is somewhere in 2009.Crazy

Never mind. Such things happen.;-)

Johan


Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere w00t

- How to post Performance Problems
- How to post data/code to get the best help


- How to prevent a sore throat after hours of presenting ppt ?


press F1 for solution, press shift+F1 for urgent solution :-D


Need a bit of Powershell? How about this

Who am I ? Sometimes this is me Alien but most of the time this is me Hehe
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search