| Author |
Topic |
|
Topaz
Posting Yak Master
199 Posts |
Posted - 2010-11-18 : 10:27:28
|
| I am trying to import some data from one table (NWsept) to another table (wce_contact).The table that I am trying to import into (wce_contact) won't allow duplicate values in the 'uniqueid' field.How can I write a query that would get SQL to check the uniqueid of NWsept with the wce_contact uniqueid and display the offending records.I'm really stuck...JT |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
Topaz
Posting Yak Master
199 Posts |
Posted - 2010-11-18 : 10:51:24
|
| The DDL constraints are exactly the same for each table.Uniqueid = VarcharJT |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-11-18 : 11:08:37
|
| in case NWSept has duplicate for a value of uniqueid, how do you determine which value you want?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
Topaz
Posting Yak Master
199 Posts |
Posted - 2010-11-18 : 11:21:10
|
| CREATE TABLE [dbo].[NWsept]( [uniqueid] [varchar](16) COLLATE Latin1_General_CI_AS NULL, [website] [varchar](75) COLLATE Latin1_General_CI_AS NULL, [expressemail] [varchar](254) COLLATE Latin1_General_CI_AS NULL, [blank] [varchar](50) COLLATE Latin1_General_CI_AS NULL) ON [PRIMARY]The other table wce_Contact has far too many fields to post on here. But their data type and character length are exactly the sameJT |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-11-18 : 11:23:53
|
quote: Originally posted by Topaz CREATE TABLE [dbo].[NWsept]( [uniqueid] [varchar](16) COLLATE Latin1_General_CI_AS NULL, [website] [varchar](75) COLLATE Latin1_General_CI_AS NULL, [expressemail] [varchar](254) COLLATE Latin1_General_CI_AS NULL, [blank] [varchar](50) COLLATE Latin1_General_CI_AS NULL) ON [PRIMARY]The other table wce_Contact has far too many fields to post on here. But their data type and character length are exactly the sameJT
you didnt answer me yet ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
Topaz
Posting Yak Master
199 Posts |
Posted - 2010-11-18 : 11:26:56
|
quote: Originally posted by visakh16 in case NWSept has duplicate for a value of uniqueid, how do you determine which value you want?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
Well, sorry for neglecting your reply.I just want to see all duplicate values from either table.JT |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-11-18 : 11:34:58
|
| but how do you insert duplicate values to table2? it has a unique constraint isnt it? then which one you would choose for its insertion is my question.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
Topaz
Posting Yak Master
199 Posts |
Posted - 2010-11-18 : 11:45:07
|
| Ok, I think what you are asking me is making sense?If it tries to insert a duplicare record, I don't want to choose any table to insert the data into. I simply don't want it to be imported.JT |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-11-18 : 11:49:13
|
| what according to you represents a duplicate record of a uniqueid? based on what other column value(s) you determine its to be neglected?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
Topaz
Posting Yak Master
199 Posts |
Posted - 2010-11-19 : 07:57:26
|
| I answered my own question with this query. Thanks for your effortsSELECT [UNIQUEID] ,[website] ,[expressemail] ,[blank] FROM [wce_site].[dbo].[NWsept] AS srcWHERE NOT EXISTS (SELECT * FROM [wce_site].[dbo].[wce_contact] AS tgt WHERE tgt.uniqueid= src.uniqueid)JT |
 |
|
|
AndrewMurphy
Master Smack Fu Yak Hacker
2916 Posts |
Posted - 2010-11-19 : 08:47:00
|
| so in effect the original questions can be re-worded."how do i insert into table#1 from table#2 and check if any of the table#2 primarykey values are already in use in table#1" |
 |
|
|
|