Solved

MSSQL Server 2008

Posted on 2009-07-14
6
163 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
ID: 24850316

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]
ID: 24850321
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
ID: 24850667
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 142

Assisted Solution

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

Author Comment

by:N R
ID: 24850713
They are Int
0
 
LVL 11

Author Comment

by:N R
ID: 24850849
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

911 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

23 Experts available now in Live!

Get 1:1 Help Now