troubleshooting Question

How do I control the SELECT DISTINCT statement?

Avatar of CubicleGuy
CubicleGuyFlag for United States of America asked on
Microsoft SQL Server 2005
19 Comments1 Solution182 ViewsLast Modified:
You can see that I need to insert values in CUSTOMERS from the INT_OH table.  I need all of those values, but the only one I want to be evaluated as being unique is the theirOrderNumber column.    The way this is currently working, the SELECT will evaluate a record as being DISTINCT even if someone just changes addresses, which we don't want it to do.

How do I get around this?

I can't find any answer in my Beginning Transact-SQL WROX book....
      (companyID, name, add1, add2, city, state, zip,country, email,
       phone, alternateCustomerID, dateAdded)
    SELECT DISTINCT @COMPANY, ordName, ordaddress, ordaddress2, ordcity, ordstate, ordzip, ordcountry, ordemail,
       ordphone, theirCustomerNumber, getdate()
        FROM INT_OH
        where theirCustomerNumber not in (select alternateCustomerID from customers where companyID = @COMPANY)
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 19 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 19 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros