Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 t-sql avod a cartesian product

Author  Topic 

jassie
Constraint Violating Yak Guru

332 Posts

Posted - 2012-12-24 : 16:45:49
For a customer, I need to load data from excel 2010 spreadsheets into a sql server 2008 r2 database for a one time set of adhoc queries. I will then run queries to obtain to look at the data based upon the user requirements.

The problem with the data is there is alot of duplicate data within different rows within the same table. When I join the various tables together, I get a cartesian product.
I am trying to determine how to run the queries I need to run without getting the cartesian product.

There are 3 tables which are: 1. a claims table by client number that has the duplicate data wtihin some of the rows. 2. a price table and 3. an authorizagtion table.

I am thinking of loading the data into temp tables in a way that the data will not be duplicated. If this is a possbility, can you tell me how to accomplish this goal?

If you have any other suggestions, can you show me code on how to accomplish this goal?

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2012-12-25 : 09:04:36
Wouldn't it be good to look at excel as to why you are getting duplicate data in same table? You can use distinct to avoid duplicates but we will need some sample data and expected output as to what exactly you are asking for?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-12-26 : 00:00:44
you need explain definition of duplicates. Does duplicate means entire row being duplicate or are you interested in only set of column values? Based on that then we can apply a logic so as populate only distinct set onto tables. Showing some sample data would make it clear for us on what exactly you're after

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

jassie
Constraint Violating Yak Guru

332 Posts

Posted - 2012-12-26 : 11:09:25
I am only interested in two columns. I do not care about the rest of the columns in each row.
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2012-12-26 : 11:46:51
Read this :
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-12-27 : 00:03:06
quote:
Originally posted by jassie

I am only interested in two columns. I do not care about the rest of the columns in each row.


ok in that case how do you want row to be retrieved for each of the groups having same value for two columns? do you've primary key (unique value) column in table to determine order? do you need earliest,latest or random row out of each group?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -