Solved

MSSQL Server 2008

Posted on 2009-07-14
6
160 Views
Last Modified: 2012-05-07
I have this select statement that works find in SQL 2000.  We recently migrated to sql server 2008 and now it doesn't work correctly, I have narrowed it down to the line:

where D.OrgID in (select distinct(I.OrgID) from Strat_Customers.dbo.Customer_CareInvoice I)

Does something need to be changed to work in 2008?  The entire select is below:
select D.DebtorID, DS.ServiceID, cast(Payments as money) - IsNull(LastPayment,0) as Payment, cast(Adjustments as money) - IsNull(LastAdjustment,0) as Adjustment, 'File Balance <> Service Balance' as Reason, cast(Payments as money), cast(Adjustments as money), LastPayment, LastAdjustment

from Strat_Customers.dbo.Customer_CareInvoice IL

inner join DebtorService DS on IL.InvoiceNumber = DS.InvoiceNo

inner join  DebtorInvoice DI  on DS.ServiceID = DI.ServiceID

inner join Debtor D on DS.DebtorID = D.DebtorID 

where D.OrgID in (select distinct(I.OrgID) from Strat_Customers.dbo.Customer_CareInvoice I)  --Change for new customer

and cast(IL.InvoiceBalance as money) <> BalanceDue

and D.StatusID in (1,2,6,8,9,10,12,20,19) --New, Suspended, Bad Address, Letters Complete, Letter Series, Payment Plan, Payment Late, Payment Breach, Invoice

Open in new window

0
Comment
Question by:N R
  • 3
  • 3
6 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
Comment Utility

you don't need distinct, actually (it won't change the results, it only might impact performance)
you have to ensure that i.OrgID is not null
where D.OrgID in (select I.OrgID from Strat_Customers.dbo.Customer_CareInvoice I where i.OrgID IS NOT NULL)

Open in new window

0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
you might also use this
where exists ( select null from Strat_Customers.dbo.Customer_CareInvoice I where i.OrgID = D.OrgID )

Open in new window

0
 
LVL 11

Author Comment

by:N R
Comment Utility
No there are never null orgid's.  I just changed it to list out the possible orgid's for that company like this:

where D.OrgID in (2534,2535,2536,2538)

Now it returns the expected results
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 500 total points
Comment Utility
what are the data types of the 2 OrgID fields?
0
 
LVL 11

Author Comment

by:N R
Comment Utility
They are Int
0
 
LVL 11

Author Comment

by:N R
Comment Utility
Strange that it doesn't work, but no big deal I can just update my SP's to have the orgid listed in there.  Thanks.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now