Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MSSQL Server 2008

Posted on 2009-07-14
6
Medium Priority
?
177 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:Nathan Riley
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 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 143

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 12

Author Comment

by:Nathan Riley
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
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 
LVL 143

Assisted Solution

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

Author Comment

by:Nathan Riley
ID: 24850713
They are Int
0
 
LVL 12

Author Comment

by:Nathan Riley
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

Quick Start: DOCKER

Sometimes you just need a Quick Start on a topic in order to begin using it.. this is just what you need to know to get up and running with Docker!

Question has a verified solution.

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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
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…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

705 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