Showing posts with label records. Show all posts
Showing posts with label records. Show all posts

Thursday, March 29, 2012

comparing two records field by field

Hi,
a stored proc should find all different fields in two records. This two
records are in two temp tables and have the same fields, but the
recordstructure can be different in every call of the stored proc.
For example, in one call i check the difference of two records from the
customer table, in the next call i check the difference of two records from
the orders table.
So i cannot use field names. In the moment i read all informations from
sysobjects and syscolumns and build sql strings for each column and execute
them to get the value as varchar and compare them.
But this is so performance- and timeconsuming, especially for records with
nearly 200 fields, that i have to find another way.
Any suggestions how to do this?
thanks for all tips,
HelmutIt depends on what your ultimate aim is (other than pain). If you're
just wanting some data analysis there's a tool called SQL data compare
that does that quite well.
If you're aiming for some nice dynamic query, you'll have to post a SQL
example (I'm afraid your description was a tad cryptic).
my approach when comparing things dynamically is to use the stored proc
sp_columns. Shove that up a temporary table, use sp_executesql to then
execute the compare, however it sounds like you're nearly doing that
(shouldn't be too bad performance wise - are you hitting the cursors a
bit too hard?)
I think you'll get better advice if you put some hard examples up of
what you're currently doing, and what you're wanting it to do.
As a load of people write as a generic response - "post your DDL and
code examples and maybe we can help more" - they say "more" as though
that was in some way helpful
anyway,
more info dude
Cheers
Will|||Hello Will,
thanks for your response. Here an example:
let's say, i have two backups of a database. Now i restore both backups and
have a stored proc wich loops through the persons table record by record.
There is an identity field, so i can read the same record from both backups
...
insert into #tbl1 select * from backup1.dbo.persons where id = 123
insert into #tbl2 select * from backup2.dbo.persons where id = 123
...
if both records exists, then i want to find the differences field by field,
for this i call another stored proc, and this proc knows, that it has one
record in #tbl1 and another record in #tbl2 with identical structure.
But it does not know, that this are records from table persons!
So it should do something like:
declare @.tblDiff (
fieldname varchar(20),
oldValue varchar(2000),
newValue varchar(2000) )
for x = 1 to #tbl1.fieldcount do begin
if (#tbl1.field[x].IsNull and not #tbl2.field[x].IsNull) or
(not #tbl1.field[x].IsNull and #tbl2.field[x].IsNull) or
(#tbl1.field[x].Value <> #tbl2.field[x].Value) then
insert into @.tblDiff values(#tbl1.field[x].Name, #tbl1.field[x].Value,
#tbl2.field[x].Value)
end
return select * from @.tblDiff
This is a pseudo code to show what i want to do. Now i need to solve this
in pure TSQL.
thanks,
Helmut|||You could try something like this, but it sounds like you're already at
this solution.
DECLARE @.Table varchar(50)
SET @.Table = 'sysobjects'
DECLARE @.IDvalue int
CREATE TABLE #Cols
(
TABLE_QUALIFIER sysname,
TABLE_OWNER sysname,
TABLE_NAME sysname,
COLUMN_NAME sysname,
DATA_TYPE smallint,
TYPE_NAME sysname,
[PRECISION] int,
LENGTH int,
SCALE smallint,
RADIX smallint,
NULLABLE smallint,
REMARKS varchar(254),
COLUMN_DEF nvarchar(4000),
SQL_DATA_TYPE smallint,
SQL_DATETIME_SUB smallint,
CHAR_OCTET_LENGTH int,
ORDINAL_POSITION int,
IS_NULLABLE varchar(254),
SS_DATA_TYPE tinyint
)
CREATE TABLE #Results(field sysname, OldValue nvarchar(4000), NewValue
nvarchar(4000))
INSERT INTO #Cols
exec sp_Columns @.Table
DECLARE Cols Cursor
FOR SELECT Colname
FROM #Cols
DECLARE @.Colname sysname
OPEN Cols
FETCH NEXT FROM cols INTO @.COlname
WHILE @.@.FETCH_STATUS = 0
BEGIN
DECLARE @.SQL nvarchar(4000)
SET @.SQL = 'INSERT INTO #Results SELECT ''' + @.Colname + ''', T1.' +
@.Colname + ', T2.' + @.ColName + ' FROM database1.dbo.' + @.tablename + '
as T1 INNER JOIN database2.dbo.' + @.TableName + ' as T2 on T1.IDField =
' + @.IDValue + ' AND T2.IDField = ' + @.IDValue + 'WHERE t1.' + @.Colname
+ ' != T2.' + @.Colname + ' AND NOT (T1.' + @.ColName + ' IS NULL AND
T2.' + @.ColName + ' IS NULL)'
exec sp_executesql @.SQL
FETCH NEXT FROM cols INTO @.COlname
END
CLOSE Cols
DEALLOCATE Cols
DROP TABLE #Cols
SELECT * FROM #REsults
DROP TABLE #Results|||Another soloution would be to use
BINARY_CHECKSUM()
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
--|||Am 6 Apr 2006 01:47:28 -0700 schrieb Jens:

> Another soloution would be to use
> BINARY_CHECKSUM()
>
> HTH, Jens Suessmeyer.
> --
> http://www.sqlserver2005.de
> --
Not really, at first, BOL says, that binary_checksum() can detect most, but
not all changes. And second, this can be used maybe in the calling function
to detect, if a difference is here. But my problem is the second step -
finding and documenting the changes.
bye, Helmut|||Hi Will,
thanks for this source. What i see at first, i need much more steps to find
the differences, so maybe you solution is faster (i hope).
But the main points are the same, information comes from sysobjects and for
every field i have to build a statement and do a sp_executesql.
But on the wend i take this source and make a benchmark and post the
result on monday.
Do you think, it would be much faster using an external stored proc?
thank you very much,
Helmut|||What are you trying to do Helmut? some kind of a retrospective audit
trail? have you considered putting triggers on your tables to maintain
this data as it changes?|||Am 6 Apr 2006 03:07:00 -0700 schrieb Will:

> What are you trying to do Helmut? some kind of a retrospective audit
> trail? have you considered putting triggers on your tables to maintain
> this data as it changes?
Yes, it should do both. For audit trail i use the data from inserted and
deleted. Working with columns_updated() is no solution, because i only
store changes and this means, if i have a record with 200 fields and only 5
fields are filled with data (and the rest is NULL), then i store only this
5 values. But when you do an insert, then columns_updated() has all bits
set.
bye, Helmut|||Helmut,
I'm afraid I think that your query is just about as fast as you'll get
it (I certainly can't think of any significant ways to improve it).
I've had one idea you could try, but I don't have time to fully
investigate it:
You could rather than performing the difference check on each column,
build up the SQL string as 'select inserted.'+colname+',
deleted.'+colname,+' CAST(CASE when insert.'+colname+' !=
deleted.'+colname+' then 1 else 0 end as bit) as ' + colname +
'ischanged' .
then build up this string for the whole set of columns, only do one
select into a temporary table, then do your inserts into your audit
table based on whether or not the bit field conameischanged has been
set to 1.
I have no idea if that will work, it has the advantage that you only
select from your 2 tables once as opposed to once per column, but it
has the divantage of needing an extra insert into a temporary table.
if you do write it then post the source and the benchmarks, I'd be
interested to know how it performs. If this isn't clear let me know,
I'll try and write some SQL this evening.
Cheers
Will

Comparing two databases for deleted records

hi ,
there is a tool that do compare between 2 databases and display deleted records an changes in schema and data ,
it's friendlly tool with beautiful gui for users.
it is called dbMaestro.
You can find it here:
http://www.extreme.co.il
You might want to check out the Red-Gate tools SQL Compare and SQL
DataCompare. I think these tools will do what you are requesting. Here is
their website: http://www.red-gate.com/
----
Need SQL Server Examples check out my website at
http://www.geocities.com/sqlserverexamples
"yaniv cohen" <yanivc@.extreme.co.il> wrote in message
news:30D974F8-F7EC-4AD7-BCC7-DDE5D9146096@.microsoft.com...
> hi ,
> there is a tool that do compare between 2 databases and display deleted
records an changes in schema and data ,
> it's friendlly tool with beautiful gui for users.
> it is called dbMaestro.
> You can find it here:
> http://www.extreme.co.il
>

Comparing two databases for deleted records

How do I compare two databases to determine deleted
records."Aboki" <anonymous@.discussions.microsoft.com> wrote in message
news:13d7001c41b24$a4d4d240$a001280a@.phx
.gbl...
> How do I compare two databases to determine deleted
> records.
Select *
from dbArchive.dbo.table1 as a
left outer join
dbUpdated.dbo.table1 as u
on a.PK = u.PK
where u.pk is null
dbArchive = the old database name
dbUpdated = the one with the rows deleted
PK = whatever the Primary Key column is
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.647 / Virus Database: 414 - Release Date: 29/03/2004|||hi ,
there is a tool that do compare between 2 databases and display deleted reco
rds an changes in schema and data ,
it's friendlly tool with beautiful gui for users.
it is called dbMaestro.
You can find it here:
http://www.extreme.co.il|||You might want to check out the Red-Gate tools SQL Compare and SQL
DataCompare. I think these tools will do what you are requesting. Here is
their website: http://www.red-gate.com/
----
----
--
Need SQL Server Examples check out my website at
http://www.geocities.com/sqlserverexamples
"yaniv cohen" <yanivc@.extreme.co.il> wrote in message
news:30D974F8-F7EC-4AD7-BCC7-DDE5D9146096@.microsoft.com...
> hi ,
> there is a tool that do compare between 2 databases and display deleted
records an changes in schema and data ,
> it's friendlly tool with beautiful gui for users.
> it is called dbMaestro.
> You can find it here:
> http://www.extreme.co.il
>

Tuesday, March 27, 2012

Comparing Tables

If I have Table A and Table B and would like to compare the records in both
tables and take the missing records from A and add them to table B. How can
I do this?
Table A and Table B are different but they have one field in common.
Thanks
Niles wrote:
> If I have Table A and Table B and would like to compare the records
> in both tables and take the missing records from A and add them to
> table B. How can I do this?
> Table A and Table B are different but they have one field in common.
> Thanks
Assuming they have keys that can be joined (I assume this is what you
mean by having one column in common).
create table #A (col1 int)
create table #B (col1 int)
insert into #A values (1)
insert into #A values (2)
insert into #A values (3)
insert into #B values (1)
insert into #B values (3)
Select * from #B
Insert Into #B (col1)
Select col1
From #A
Where Not Exists (
Select * from #B Where #B.col1 = #A.col1)
Select * from #B
David Gugick
Imceda Software
www.imceda.com
|||This query will do it...
INSERT INTO B (COLUMN1,COLUMN2)
SELECT (COLUMN1,COLUMN2)
FROM A
WHERE NOT EXISTS
(SELECT *
FROM B
WHERE A.COMMON_FIELD = B.COMMON_FIELD)
Arshad
arshadmd@.gmail.com
"Niles" wrote:

> If I have Table A and Table B and would like to compare the records in both
> tables and take the missing records from A and add them to table B. How can
> I do this?
> Table A and Table B are different but they have one field in common.
> Thanks
|||Well, I am trying to insert just the primary key From A, the rest of the
columns I want to enter another value such as 0 or some comment. How do I do
that?
"Arshad" wrote:
[vbcol=seagreen]
> This query will do it...
> INSERT INTO B (COLUMN1,COLUMN2)
> SELECT (COLUMN1,COLUMN2)
> FROM A
> WHERE NOT EXISTS
> (SELECT *
> FROM B
> WHERE A.COMMON_FIELD = B.COMMON_FIELD)
> Arshad
> arshadmd@.gmail.com
> "Niles" wrote:

Comparing Tables

If I have Table A and Table B and would like to compare the records in both
tables and take the missing records from A and add them to table B. How can
I do this?
Table A and Table B are different but they have one field in common.
ThanksNiles wrote:
> If I have Table A and Table B and would like to compare the records
> in both tables and take the missing records from A and add them to
> table B. How can I do this?
> Table A and Table B are different but they have one field in common.
> Thanks
Assuming they have keys that can be joined (I assume this is what you
mean by having one column in common).
create table #A (col1 int)
create table #B (col1 int)
insert into #A values (1)
insert into #A values (2)
insert into #A values (3)
insert into #B values (1)
insert into #B values (3)
Select * from #B
Insert Into #B (col1)
Select col1
From #A
Where Not Exists (
Select * from #B Where #B.col1 = #A.col1)
Select * from #B
David Gugick
Imceda Software
www.imceda.com|||This query will do it...
INSERT INTO B (COLUMN1,COLUMN2)
SELECT (COLUMN1,COLUMN2)
FROM A
WHERE NOT EXISTS
(SELECT *
FROM B
WHERE A.COMMON_FIELD = B.COMMON_FIELD)
Arshad
arshadmd@.gmail.com
"Niles" wrote:
> If I have Table A and Table B and would like to compare the records in both
> tables and take the missing records from A and add them to table B. How can
> I do this?
> Table A and Table B are different but they have one field in common.
> Thanks|||Well, I am trying to insert just the primary key From A, the rest of the
columns I want to enter another value such as 0 or some comment. How do I do
that?
"Arshad" wrote:
> This query will do it...
> INSERT INTO B (COLUMN1,COLUMN2)
> SELECT (COLUMN1,COLUMN2)
> FROM A
> WHERE NOT EXISTS
> (SELECT *
> FROM B
> WHERE A.COMMON_FIELD = B.COMMON_FIELD)
> Arshad
> arshadmd@.gmail.com
> "Niles" wrote:
> > If I have Table A and Table B and would like to compare the records in both
> > tables and take the missing records from A and add them to table B. How can
> > I do this?
> > Table A and Table B are different but they have one field in common.
> > Thankssqlsql

Comparing Table Records

Hi everyone,

I’m looking for any recommendations or ideas for achieving a task I am currently doing in a much more efficient way or form. I am currently running a process that takes data in an Excel Worksheet and populates a SQL Table. Each record within that SQL Table is then read by another system to perform workflow related tasks. The problem I am having is reading each SQL record all the time, looking for delta changes. As you can imagine, this can be pretty time consuming if each record contains many column values with thousands of records in the DB.

I’m using a DTS Package to transform the data from Excel to SQL. The package is extremely dumb, in a sense all it does before doing a bulk import is running a “TRUNCATE TABLE [table]” command against the target to clear all the values before reloading.

I created a trigger in my primary table, which listens for delta updates. Upon a record update, it makes the record change within the primary table, additionally writing that record value to another Delta_Table within the Database. The benefit there is my outside system only needs to read the delta table to make updates rather than the primary which eliminates the need to parse through each record one by one, all the time. As you see, this cuts the read time from my outside system more than half.

I guess what I’d like to do is see if there is a better way to load the table without having to truncate all the records. Ideas?

Thanks Everyone!

Can you use Integration services. If so there is a slowly changing dimension component that you set to compare the loading data against the stored data and then decide what to do.

You could load your data into another table then do the following,

DELETE any records that exist in your target table that don't exist in the laoded table

UPDATE any records that exist but are different

INSERT any new records

you can then have a trigger that populates your diff table.

I prefer the Integration services option, I believe something similar is available in DTS

Comparing similarities in 2 tables - sql query

hi, I have been working on this for about 3 hours now and I can't get any
further:
I have 2 tables (one table for january records and 1 table for june records)
I need to find every instance where a drug name and quantity dispensed are
the exact same in both tables
Then I need to loop through (or can it be done in the query?) each instance
and display the RX numbers along with the drug names and quantities from each
table where that happens (rx from the january table will be different from
the rx in the june table)
(drug_name,quantity_dispensed and rx is a field which resides in both tables)
something like this:
drug quantity janrx junerx
-- -- -- --
aspirin 15 43323 8879676
aspirin 15 2322 12313
codeine 10 1222 989898
I probably did not make that clear but I will be glad to re-word it if
anyone is available to help me.
Thank-You
John
John
Don't work on sunday:-)))))))
create table #june
(
[id] int not null primary key,
drug varchar(50) not null,
qt int
)
insert into #june values (1,'aspirin',15)
insert into #june values (2,'codein',20)
insert into #june values (3,'codein',40)
insert into #june values (4,'optalgin',100)
create table #jan
(
[id] int not null primary key,
drug varchar(50) not null,
qt int
)
insert into #jan values (1,'aspirin',15)
insert into #jan values (2,'codein',20)
insert into #jan values (3,'codein',10)
insert into #jan values (4,'junk',100)
select j.drug,j.qt from #june j join #jan
on j.drug=#jan.drug and j.qt=#jan.qt
"John Jasper" <JohnJasper@.discussions.microsoft.com> wrote in message
news:5E1DF03B-88E7-4C5C-9D76-F162DCDA1013@.microsoft.com...
> hi, I have been working on this for about 3 hours now and I can't get any
> further:
> I have 2 tables (one table for january records and 1 table for june
> records)
> I need to find every instance where a drug name and quantity dispensed are
> the exact same in both tables
> Then I need to loop through (or can it be done in the query?) each
> instance
> and display the RX numbers along with the drug names and quantities from
> each
> table where that happens (rx from the january table will be different from
> the rx in the june table)
> (drug_name,quantity_dispensed and rx is a field which resides in both
> tables)
> something like this:
> drug quantity janrx junerx
> -- -- -- --
> aspirin 15 43323 8879676
> aspirin 15 2322 12313
> codeine 10 1222 989898
> I probably did not make that clear but I will be glad to re-word it if
> anyone is available to help me.
>
> Thank-You
> John
>
|||Thanks for such a quick reply !
I don't understand where those tables are created - they don't show up in
the Enterprise manager and when I run the query after i run those create
table queries - it says: invalid object #jan
invalid object #june
"Uri Dimant" wrote:

> John
> Don't work on sunday:-)))))))
>
> create table #june
> (
> [id] int not null primary key,
> drug varchar(50) not null,
> qt int
> )
> insert into #june values (1,'aspirin',15)
> insert into #june values (2,'codein',20)
> insert into #june values (3,'codein',40)
> insert into #june values (4,'optalgin',100)
>
> create table #jan
> (
> [id] int not null primary key,
> drug varchar(50) not null,
> qt int
> )
> insert into #jan values (1,'aspirin',15)
> insert into #jan values (2,'codein',20)
> insert into #jan values (3,'codein',10)
> insert into #jan values (4,'junk',100)
>
> --
> select j.drug,j.qt from #june j join #jan
> on j.drug=#jan.drug and j.qt=#jan.qt
>
>
> "John Jasper" <JohnJasper@.discussions.microsoft.com> wrote in message
> news:5E1DF03B-88E7-4C5C-9D76-F162DCDA1013@.microsoft.com...
>
>
|||John
Those tables are temporary tables which are created in tempdb database. I
did it just for testing.
The matter is does it work or it doesn't (i meant the solution)?
"John Jasper" <JohnJasper@.discussions.microsoft.com> wrote in message
news:E67FB1FB-5092-4CA2-B3C3-C59C080910EB@.microsoft.com...[vbcol=seagreen]
> Thanks for such a quick reply !
> I don't understand where those tables are created - they don't show up in
> the Enterprise manager and when I run the query after i run those create
> table queries - it says: invalid object #jan
> invalid object #june
> "Uri Dimant" wrote:

Comparing similarities in 2 tables - sql query

hi, I have been working on this for about 3 hours now and I can't get any
further:
I have 2 tables (one table for january records and 1 table for june records)
I need to find every instance where a drug name and quantity dispensed are
the exact same in both tables
Then I need to loop through (or can it be done in the query?) each instance
and display the RX numbers along with the drug names and quantities from each
table where that happens (rx from the january table will be different from
the rx in the june table)
(drug_name,quantity_dispensed and rx is a field which resides in both tables)
something like this:
drug quantity janrx junerx
-- -- -- --
aspirin 15 43323 8879676
aspirin 15 2322 12313
codeine 10 1222 989898
I probably did not make that clear but I will be glad to re-word it if
anyone is available to help me.
Thank-You
JohnJohn
Don't work on sunday:-)))))))
create table #june
(
[id] int not null primary key,
drug varchar(50) not null,
qt int
)
insert into #june values (1,'aspirin',15)
insert into #june values (2,'codein',20)
insert into #june values (3,'codein',40)
insert into #june values (4,'optalgin',100)
create table #jan
(
[id] int not null primary key,
drug varchar(50) not null,
qt int
)
insert into #jan values (1,'aspirin',15)
insert into #jan values (2,'codein',20)
insert into #jan values (3,'codein',10)
insert into #jan values (4,'junk',100)
select j.drug,j.qt from #june j join #jan
on j.drug=#jan.drug and j.qt=#jan.qt
"John Jasper" <JohnJasper@.discussions.microsoft.com> wrote in message
news:5E1DF03B-88E7-4C5C-9D76-F162DCDA1013@.microsoft.com...
> hi, I have been working on this for about 3 hours now and I can't get any
> further:
> I have 2 tables (one table for january records and 1 table for june
> records)
> I need to find every instance where a drug name and quantity dispensed are
> the exact same in both tables
> Then I need to loop through (or can it be done in the query?) each
> instance
> and display the RX numbers along with the drug names and quantities from
> each
> table where that happens (rx from the january table will be different from
> the rx in the june table)
> (drug_name,quantity_dispensed and rx is a field which resides in both
> tables)
> something like this:
> drug quantity janrx junerx
> -- -- -- --
> aspirin 15 43323 8879676
> aspirin 15 2322 12313
> codeine 10 1222 989898
> I probably did not make that clear but I will be glad to re-word it if
> anyone is available to help me.
>
> Thank-You
> John
>|||Thanks for such a quick reply !
I don't understand where those tables are created - they don't show up in
the Enterprise manager and when I run the query after i run those create
table queries - it says: invalid object #jan
invalid object #june
"Uri Dimant" wrote:
> John
> Don't work on sunday:-)))))))
>
> create table #june
> (
> [id] int not null primary key,
> drug varchar(50) not null,
> qt int
> )
> insert into #june values (1,'aspirin',15)
> insert into #june values (2,'codein',20)
> insert into #june values (3,'codein',40)
> insert into #june values (4,'optalgin',100)
>
> create table #jan
> (
> [id] int not null primary key,
> drug varchar(50) not null,
> qt int
> )
> insert into #jan values (1,'aspirin',15)
> insert into #jan values (2,'codein',20)
> insert into #jan values (3,'codein',10)
> insert into #jan values (4,'junk',100)
>
> --
> select j.drug,j.qt from #june j join #jan
> on j.drug=#jan.drug and j.qt=#jan.qt
>
>
> "John Jasper" <JohnJasper@.discussions.microsoft.com> wrote in message
> news:5E1DF03B-88E7-4C5C-9D76-F162DCDA1013@.microsoft.com...
> > hi, I have been working on this for about 3 hours now and I can't get any
> > further:
> >
> > I have 2 tables (one table for january records and 1 table for june
> > records)
> >
> > I need to find every instance where a drug name and quantity dispensed are
> > the exact same in both tables
> >
> > Then I need to loop through (or can it be done in the query?) each
> > instance
> > and display the RX numbers along with the drug names and quantities from
> > each
> > table where that happens (rx from the january table will be different from
> > the rx in the june table)
> >
> > (drug_name,quantity_dispensed and rx is a field which resides in both
> > tables)
> >
> > something like this:
> >
> > drug quantity janrx junerx
> > -- -- -- --
> > aspirin 15 43323 8879676
> > aspirin 15 2322 12313
> > codeine 10 1222 989898
> >
> > I probably did not make that clear but I will be glad to re-word it if
> > anyone is available to help me.
> >
> >
> > Thank-You
> >
> > John
> >
>
>|||John
Those tables are temporary tables which are created in tempdb database. I
did it just for testing.
The matter is does it work or it doesn't (i meant the solution)?
"John Jasper" <JohnJasper@.discussions.microsoft.com> wrote in message
news:E67FB1FB-5092-4CA2-B3C3-C59C080910EB@.microsoft.com...
> Thanks for such a quick reply !
> I don't understand where those tables are created - they don't show up in
> the Enterprise manager and when I run the query after i run those create
> table queries - it says: invalid object #jan
> invalid object #june
> "Uri Dimant" wrote:
>> John
>> Don't work on sunday:-)))))))
>>
>> create table #june
>> (
>> [id] int not null primary key,
>> drug varchar(50) not null,
>> qt int
>> )
>> insert into #june values (1,'aspirin',15)
>> insert into #june values (2,'codein',20)
>> insert into #june values (3,'codein',40)
>> insert into #june values (4,'optalgin',100)
>>
>> create table #jan
>> (
>> [id] int not null primary key,
>> drug varchar(50) not null,
>> qt int
>> )
>> insert into #jan values (1,'aspirin',15)
>> insert into #jan values (2,'codein',20)
>> insert into #jan values (3,'codein',10)
>> insert into #jan values (4,'junk',100)
>>
>> --
>> select j.drug,j.qt from #june j join #jan
>> on j.drug=#jan.drug and j.qt=#jan.qt
>>
>>
>> "John Jasper" <JohnJasper@.discussions.microsoft.com> wrote in message
>> news:5E1DF03B-88E7-4C5C-9D76-F162DCDA1013@.microsoft.com...
>> > hi, I have been working on this for about 3 hours now and I can't get
>> > any
>> > further:
>> >
>> > I have 2 tables (one table for january records and 1 table for june
>> > records)
>> >
>> > I need to find every instance where a drug name and quantity dispensed
>> > are
>> > the exact same in both tables
>> >
>> > Then I need to loop through (or can it be done in the query?) each
>> > instance
>> > and display the RX numbers along with the drug names and quantities
>> > from
>> > each
>> > table where that happens (rx from the january table will be different
>> > from
>> > the rx in the june table)
>> >
>> > (drug_name,quantity_dispensed and rx is a field which resides in both
>> > tables)
>> >
>> > something like this:
>> >
>> > drug quantity janrx junerx
>> > -- -- -- --
>> > aspirin 15 43323 8879676
>> > aspirin 15 2322 12313
>> > codeine 10 1222 989898
>> >
>> > I probably did not make that clear but I will be glad to re-word it if
>> > anyone is available to help me.
>> >
>> >
>> > Thank-You
>> >
>> > John
>> >
>>sqlsql

Comparing similarities in 2 tables - sql query

hi, I have been working on this for about 3 hours now and I can't get any
further:
I have 2 tables (one table for january records and 1 table for june records)
I need to find every instance where a drug name and quantity dispensed are
the exact same in both tables
Then I need to loop through (or can it be done in the query?) each instance
and display the RX numbers along with the drug names and quantities from eac
h
table where that happens (rx from the january table will be different from
the rx in the june table)
(drug_name,quantity_dispensed and rx is a field which resides in both tables
)
something like this:
drug quantity janrx junerx
-- -- -- --
aspirin 15 43323 8879676
aspirin 15 2322 12313
codeine 10 1222 989898
I probably did not make that clear but I will be glad to re-word it if
anyone is available to help me.
Thank-You
JohnJohn
Don't work on sunday:-)))))))
create table #june
(
[id] int not null primary key,
drug varchar(50) not null,
qt int
)
insert into #june values (1,'aspirin',15)
insert into #june values (2,'codein',20)
insert into #june values (3,'codein',40)
insert into #june values (4,'optalgin',100)
create table #jan
(
[id] int not null primary key,
drug varchar(50) not null,
qt int
)
insert into #jan values (1,'aspirin',15)
insert into #jan values (2,'codein',20)
insert into #jan values (3,'codein',10)
insert into #jan values (4,'junk',100)
select j.drug,j.qt from #june j join #jan
on j.drug=#jan.drug and j.qt=#jan.qt
"John Jasper" <JohnJasper@.discussions.microsoft.com> wrote in message
news:5E1DF03B-88E7-4C5C-9D76-F162DCDA1013@.microsoft.com...
> hi, I have been working on this for about 3 hours now and I can't get any
> further:
> I have 2 tables (one table for january records and 1 table for june
> records)
> I need to find every instance where a drug name and quantity dispensed are
> the exact same in both tables
> Then I need to loop through (or can it be done in the query?) each
> instance
> and display the RX numbers along with the drug names and quantities from
> each
> table where that happens (rx from the january table will be different from
> the rx in the june table)
> (drug_name,quantity_dispensed and rx is a field which resides in both
> tables)
> something like this:
> drug quantity janrx junerx
> -- -- -- --
> aspirin 15 43323 8879676
> aspirin 15 2322 12313
> codeine 10 1222 989898
> I probably did not make that clear but I will be glad to re-word it if
> anyone is available to help me.
>
> Thank-You
> John
>|||Thanks for such a quick reply !
I don't understand where those tables are created - they don't show up in
the Enterprise manager and when I run the query after i run those create
table queries - it says: invalid object #jan
invalid object #june
"Uri Dimant" wrote:

> John
> Don't work on sunday:-)))))))
>
> create table #june
> (
> [id] int not null primary key,
> drug varchar(50) not null,
> qt int
> )
> insert into #june values (1,'aspirin',15)
> insert into #june values (2,'codein',20)
> insert into #june values (3,'codein',40)
> insert into #june values (4,'optalgin',100)
>
> create table #jan
> (
> [id] int not null primary key,
> drug varchar(50) not null,
> qt int
> )
> insert into #jan values (1,'aspirin',15)
> insert into #jan values (2,'codein',20)
> insert into #jan values (3,'codein',10)
> insert into #jan values (4,'junk',100)
>
> --
> select j.drug,j.qt from #june j join #jan
> on j.drug=#jan.drug and j.qt=#jan.qt
>
>
> "John Jasper" <JohnJasper@.discussions.microsoft.com> wrote in message
> news:5E1DF03B-88E7-4C5C-9D76-F162DCDA1013@.microsoft.com...
>
>|||John
Those tables are temporary tables which are created in tempdb database. I
did it just for testing.
The matter is does it work or it doesn't (i meant the solution)?
"John Jasper" <JohnJasper@.discussions.microsoft.com> wrote in message
news:E67FB1FB-5092-4CA2-B3C3-C59C080910EB@.microsoft.com...[vbcol=seagreen]
> Thanks for such a quick reply !
> I don't understand where those tables are created - they don't show up in
> the Enterprise manager and when I run the query after i run those create
> table queries - it says: invalid object #jan
> invalid object #june
> "Uri Dimant" wrote:
>

Comparing Records

Is there a Stored Procedure that compares 2 records and give you the
diffrences between them? Or do I have to manually compare each record?You will have to write one depending on what you want to compare and how you
want to retrieve the differences. For direct data comparison there are
certain 3rd party tools from companies like RedGate which you can buy off
the shelf.
Anith|||I wanted to do this from a trigger. ie see what changes there are from
the old record to the new record.|||You'd have to use the inserted and deleted tables within the trigger to do
this. Check out the topic CREATE TRIGGER in SQL Server Books Online; there
are certain examples which details how you can use them.
If you still have difficulty in coming up with a required solution, pl.
refer to www.aspfaq.com/5006 and post required information for others to
repro your problem.
Anith|||Thanks, I know how to do triggers. But you answered my question so
thanks.

Sunday, March 25, 2012

Comparing millions of records from file A and B

I'm trying to compare about 28 million records (270 length) from table A and B using the Lookup task as described in this forum. The process works fine with about two million records or so on my desktop ( p.4 3.39GHz, 1.5 GB Ram), but hangs with the amount of data I'm trying to process. I tried using full and partial caching, but to no avail. I'm thinking this is a hardware resource problem. So, does anyone has any recommendation on the hardware needed for this kind of operation and/or suggestion? Thanks in advance...

What are you interested in?

The "failures" or the "matches"

Try "tossing away" the data that you dont need so you can free the resources. How many Rows are in the Lookup table?

|||I'm interested in the failures. I want all that is in A that is not in B. The lookup table contains 13,730,718 rows. Thanks.|||

Take a look at the TableDifference component available on the http://www.sqlbi.eu site. Works great for a large number of records and can detect rows that do not exist in one or the other of two inputs as well as changes in the records. A few caveats to know about:

1. The inputs to the TableDifference component must be sorted. Since your data is coming from flat files, you will either have to (a) use a Sort on each source or (b) land the data to a staging table of some type and then requery from there using an order by on the queries.

2. The schema between the inputs to TableDifference must match. That means column names as well as data types.

3. There are some cases where one or the other of the inputs arrives at the TableDifference component faster than the other. There are some additional components available on the site that address these types of racing conditions.

Dave F.

|||

Natee wrote:

I'm interested in the failures. I want all that is in A that is not in B. The lookup table contains 13,730,718 rows. Thanks.

If you Lookup Table contains that main rows you will have a hard time with that configuration. Just in order to cache all those rows you will need approx 3.7 Gig of memory. And ontop of that you will have to add a few bytes for an index. If you are not caching the data, it means it will have to be looked up in the DB which is very timeconsuming and for millions of rows that will add up. To execute this I would suggest a box of at least 4-5 Gig (rather more) of main memory, and select to cache the smaller of those 2 tables. There wont be any way to optimize this cleaning unless you can get the data either sorted correctly (So the server will be able to use smart nested loops like in the component mentioned) or expand the memory so the whole looup table will fit into memory.

What will the Data look like? Are there many rows that are "almost" alike? If so there could be a fancy solution (thinking along the lines of using a tree structure to compress data)... But It would deffinitly be easier to find a server with some ram to handle this task.

Edit: Are the 2 Tabels in the same DB? Do Indexes exist on those that can be used to order the Data? If so you might want to write single querry to do this... You might need to use a join hint and force a merge join on the data...

|||I have developed and fully documented a method for doing mass record comparisons and updates using the Script Component instead of the Lookup component. We also tried to use the Lookup component for a similar task and ran into too many issues. This Script Component technique is currently working great for us! Plus, it's even easier to implement than the Lookup component! Let me know what you think.

Here is a URL for the complete documentation for this method:
http://www.mathgv.com/sql2005docs/SSISTransformScriptETL.htm

Thanks,
Greg Van Mullem
|||I'm sincerely grateful to all for your response and for pointing me in the right direction. I checked out the site Dave directed me to and successfully ran this operation on my laptop with a GB of Ram within an hour. I could not believe it after struggling with this for a week. I'll definitely check out Greg's solution too. Many, many thanks again for your help.|||

Greg Van Mullem wrote:

I have developed and fully documented a method for doing mass record comparisons and updates using the Script Component instead of the Lookup component. We also tried to use the Lookup component for a similar task and ran into too many issues. This Script Component technique is currently working great for us! Plus, it's even easier to implement than the Lookup component! Let me know what you think.
Here is a URL for the complete documentation for this method:
http://www.mathgv.com/sql2005docs/SSISTransformScriptETL.htm
Thanks,
Greg Van Mullem

Hi Greg,

Fascinating stuff. You've got some really valuable code to share up there.

I'm slightly sceptical as to why this is actually necassary though. Your justification for doing it all in code seems to be that using lookups "needlessly fills up the destination databases transaction log with hoards of update commands" and "It prevents counting the records that actually needed to be updated." Well did you explore using LOOKUPs to find out whether a row that already exists has actually changed or not? Or even a derived column/conditional split component subsequent to your LOOKUp that compares the values in the pipeline with the values in the LOOKUP dataset? That is eminently possible and will solve the two problems that you mention here.

Great work though.

-Jamie

|||I'm posting all my replys about this stuff in this other extremely simular thread.

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=719997&SiteID=1&mode=1

Please go to that thread for further info. I hate trying to maintian a coversation in 2 different threads at the same time so I'm not going to post in this thread any more.

Thanks,
Greg Van Mullem

Comparing millions of records from file A and B

I'm trying to compare about 28 million records (270 length) from table A and B using the Lookup task as described in this forum. The process works fine with about two million records or so on my desktop ( p.4 3.39GHz, 1.5 GB Ram), but hangs with the amount of data I'm trying to process. I tried using full and partial caching, but to no avail. I'm thinking this is a hardware resource problem. So, does anyone has any recommendation on the hardware needed for this kind of operation and/or suggestion? Thanks in advance...

What are you interested in?

The "failures" or the "matches"

Try "tossing away" the data that you dont need so you can free the resources. How many Rows are in the Lookup table?

|||I'm interested in the failures. I want all that is in A that is not in B. The lookup table contains 13,730,718 rows. Thanks.|||

Take a look at the TableDifference component available on the http://www.sqlbi.eu site. Works great for a large number of records and can detect rows that do not exist in one or the other of two inputs as well as changes in the records. A few caveats to know about:

1. The inputs to the TableDifference component must be sorted. Since your data is coming from flat files, you will either have to (a) use a Sort on each source or (b) land the data to a staging table of some type and then requery from there using an order by on the queries.

2. The schema between the inputs to TableDifference must match. That means column names as well as data types.

3. There are some cases where one or the other of the inputs arrives at the TableDifference component faster than the other. There are some additional components available on the site that address these types of racing conditions.

Dave F.

|||

Natee wrote:

I'm interested in the failures. I want all that is in A that is not in B. The lookup table contains 13,730,718 rows. Thanks.

If you Lookup Table contains that main rows you will have a hard time with that configuration. Just in order to cache all those rows you will need approx 3.7 Gig of memory. And ontop of that you will have to add a few bytes for an index. If you are not caching the data, it means it will have to be looked up in the DB which is very timeconsuming and for millions of rows that will add up. To execute this I would suggest a box of at least 4-5 Gig (rather more) of main memory, and select to cache the smaller of those 2 tables. There wont be any way to optimize this cleaning unless you can get the data either sorted correctly (So the server will be able to use smart nested loops like in the component mentioned) or expand the memory so the whole looup table will fit into memory.

What will the Data look like? Are there many rows that are "almost" alike? If so there could be a fancy solution (thinking along the lines of using a tree structure to compress data)... But It would deffinitly be easier to find a server with some ram to handle this task.

Edit: Are the 2 Tabels in the same DB? Do Indexes exist on those that can be used to order the Data? If so you might want to write single querry to do this... You might need to use a join hint and force a merge join on the data...

|||I have developed and fully documented a method for doing mass record comparisons and updates using the Script Component instead of the Lookup component. We also tried to use the Lookup component for a similar task and ran into too many issues. This Script Component technique is currently working great for us! Plus, it's even easier to implement than the Lookup component! Let me know what you think.

Here is a URL for the complete documentation for this method:
http://www.mathgv.com/sql2005docs/SSISTransformScriptETL.htm

Thanks,
Greg Van Mullem|||I'm sincerely grateful to all for your response and for pointing me in the right direction. I checked out the site Dave directed me to and successfully ran this operation on my laptop with a GB of Ram within an hour. I could not believe it after struggling with this for a week. I'll definitely check out Greg's solution too. Many, many thanks again for your help.|||

Greg Van Mullem wrote:

I have developed and fully documented a method for doing mass record comparisons and updates using the Script Component instead of the Lookup component. We also tried to use the Lookup component for a similar task and ran into too many issues. This Script Component technique is currently working great for us! Plus, it's even easier to implement than the Lookup component! Let me know what you think.
Here is a URL for the complete documentation for this method:
http://www.mathgv.com/sql2005docs/SSISTransformScriptETL.htm
Thanks,
Greg Van Mullem

Hi Greg,

Fascinating stuff. You've got some really valuable code to share up there.

I'm slightly sceptical as to why this is actually necassary though. Your justification for doing it all in code seems to be that using lookups "needlessly fills up the destination databases transaction log with hoards of update commands" and "It prevents counting the records that actually needed to be updated." Well did you explore using LOOKUPs to find out whether a row that already exists has actually changed or not? Or even a derived column/conditional split component subsequent to your LOOKUp that compares the values in the pipeline with the values in the LOOKUP dataset? That is eminently possible and will solve the two problems that you mention here.

Great work though.

-Jamie

|||I'm posting all my replys about this stuff in this other extremely simular thread.

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=719997&SiteID=1&mode=1

Please go to that thread for further info. I hate trying to maintian a coversation in 2 different threads at the same time so I'm not going to post in this thread any more.

Thanks,
Greg Van Mullemsqlsql

Comparing fields within a select

Hi there,

Is it possible for a query to return all the records in a table which have the same value in a given column?

SELECT * FROM table1 WHERE field1 = 2

..would return all the records from table1 which have a field1 value of 2 but I don't want to specify the value - just that all the records have the same value.

Cheers,

WT.I'm not sure I understand what you're trying to do. Are you trying to return all records where the values in field1 are repeated? Can you provide an example to clarify?|||I think I understand what you are asking for. You're looking for all records where there are duplicates in field1.
Kind of the opposite of a DISTINCT query.
If you do a self join you can get what you want.
Here's the generic form...
SELECT * FROM table1 WHERE field1 IN (SELECT DISTINCT T1.field1 FROM table1.T1, table1.T2 WHERE T1.field1=T2.field1 AND T1.Field2<>T2.field2)

Here's an example using the Customers table from NorthWind that will return all the customers in cities where there is more than one customer in that city...
SELECT DISTINCT C1.CITY FROM Customers C1, Customers C2 WHERE C1.City = C2.City and C1.CustomerID <> C2.CustomerID|||An easier way to do this (if I understand your question):

SELECT CompanyID, COUNT(*)
Companies
GROUP BY CompanyID
HAVING COUNT(*) > 1

comparing DateTime in UK Format

Hello friends,

I am trying to return all records between 2 dates. The Date columns are in DateTime format, and i am ignoring the timestamp. The user should be able to input UK Date Format (dd/mm/yyyy) and return the rows. This sql code works fine for American date format, but i get an error: converting from varchar to datetime when i put in a UK format. eg. 22/11/06. Please advise on this problem! many thanks!

ALTER PROCEDURE SalaryBetweenDates
(

@.WeekStart datetime,

@.WeekEnd datetime
)
AS

BEGIN
SET @.WeekStart = (SELECT REPLACE(CONVERT(DATETIME,@.WeekStart ,103),' ','-'))
SET @.WeekEnd = (SELECT REPLACE(CONVERT(DATETIME,@.WeekEnd ,103),' ','-'))
END

BEGIN
SELECT s.StaffNo,s.StaffName,s.StaffAddress, s.HourlyRate,
sh.HoursWorked, CONVERT(varchar(12), sh.WeekStart, 103) AS StartDate, CONVERT(varchar(12), sh.WeekEnd, 103)As EndDate,(sh.HoursWorked * s.HourlyRate)"Salary"
From Staff As S INNER JOIN StaffHours As Sh
On S.StaffNo = Sh.StaffNo
WHERE sh.WeekStart >= (@.WeekStart)
AND sh.WeekEnd <= (@.WeekEnd)

FOR XML RAW ('paySlip'), root('Staff'), ELEMENTS XSINIL
END

ReturnYou need to convert the UK format date into a format that Sql can read.
I always use the following ones
'YYYY-MM-DD' for date
'YYYY-MM-DD HH:NN:SS' for date & time
use exactly as is... don't change the sperators

so '22/11/06' should be passed to sqlserver as '2006-11-22'|||

If you want to be able to call the procedure like this

EXEC SalaryBetweenDates '22/11/06', '1/12/06'

you're going to have to make the procedure parameters varchars and write some string handling code to figure out the strings that are passed in. I'd recommend that you leave it as it is and have the application pass dates in the format that SQL Server expects, if necessary have the application do the work at figuring out what date the user actually entered.

|||

thanks for your help guys. I set the parameters as strings in the end, and used REPLACE(CONVERT) to handle the function

:-)

Comparing Dates.

Hi All,

I have a database field (datestamp) which returns the date the records were inserted into the database. The datestamp was created with the now(); function in .net and is in the following format:5/23/2006 2:27:45 AM

I basically want to return all records that were inputted more than 28 days ago. I have had alook though some other posts and below is the closest query that i could find but unfortunately it does not work for me.

SELECT id, datestamp
FROM table
WHERE datestamp > DateAdd(d, 28, GetDate())

Thanks in advance,

Jake

You are looking for a date 28 days ago, so try -28:

SELECT id, datestamp
FROM table
WHERE datestamp > DateAdd(d,-28, GetDate())

|||

Spot on Douglas, thankyou for you quick reply!

Jake

Thursday, March 22, 2012

Comparing data in two tables to find missing records

I have two tables of book information. One that has descriptions of the
book in it, and the isbn, and the other that has the book title,
inventory data, prices, the isbn.

Because of some techncal constraints I won't get into now, I can't
combine them both into one table. No problem. Things are going fine as
long as there is a description in the one table to corrispond to the
isbn and other data in the other table.

However, about half of the products are not yet entered into the
descrition table. I'd like to run a sql query that pulls up all the
isbns that don't exist in the other. In other words, I'd like to get a
query that tells me exactly which isbns do not yet have descrition data
in them. I know there is some sql that says to search from one file
where the number does not exist in the other, but it slips my mind. Can
someone help me on this please?

Thank you!

Bill

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!Bill,

You can use one of these queries:

select *
from Titles
where not exists(select * from Descriptions where Descriptions.isbn =
Titles.isbn)

OR

select *
from Titles
where isbn not in (select isbn from Descriptions)

OR

select Titles.*
from Titles left outer join Descriptions on Descriptions.isbn =
Titles.isbn
where Descriptions.isbn is null

Shervin

"Bill" <BillZimmerman@.gospellight.com> wrote in message
news:3f8c7948$0$200$75868355@.news.frii.net...
> I have two tables of book information. One that has descriptions of the
> book in it, and the isbn, and the other that has the book title,
> inventory data, prices, the isbn.
> Because of some techncal constraints I won't get into now, I can't
> combine them both into one table. No problem. Things are going fine as
> long as there is a description in the one table to corrispond to the
> isbn and other data in the other table.
> However, about half of the products are not yet entered into the
> descrition table. I'd like to run a sql query that pulls up all the
> isbns that don't exist in the other. In other words, I'd like to get a
> query that tells me exactly which isbns do not yet have descrition data
> in them. I know there is some sql that says to search from one file
> where the number does not exist in the other, but it slips my mind. Can
> someone help me on this please?
> Thank you!
>
> Bill
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!|||Dear Shervin:

Thank you! It worked like a charm.

All the best,

Bill

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!sqlsql

Comparing contents of one row to multiple rows in another table?

Hi,

I've a bunch of records that may contain data that I'm after. For example:

This is a fake title [electronic resource]. 1997.

I have a very small table (~10 rows) of things like '[electronic resource]'

Is there any way to see if my record contains any of the 'target' items in the other table?

Need more information. Can't able to follow you. Can you post more info pls...

Tuesday, March 20, 2012

Comparing 2 records

I'm trying to write an SQL statement that would allow me to compare 2 records from the same table.

Basically, I have a table of events for an object with a column that contains when the event started but not when the event ended. An object in the table will have at least 2 events so I could take the start time of the second event to determine the end time of the first event. Can this be done using SQL? I know I can do it by writing a stored procedure and storing the results in a table, but was hoping not to have to do this.

Any help will be appreciated.select t1.id
, t1.starttime as starttime
, t2.starttime as endtime
from events t1
inner
join events t2
on t1.id = t2.id
and t1.starttime < t2.starttime use left outer join instead of inner if you want to pick up events that have started but not finished

rudy
http://r937.com/|||Thanks Rudy!|||Actually, the version of Oracle I am using did not support "inner join", so what ended up working was:

select t1.id, t1.date, t2.date
from event t1, event t2
where t1.id = t2.id
and t1.date < t2.date|||good one, and thanks for the update

i keep forgetting that there are still lots of companies and individuals out there who are in no hurry to install the latest and greatest software

e.g. i'm still on access 97 on my desktop, and have no plans to upgrade ever

by the way, what side does the plus sign go on if you wanted to join event t1 left outer event t2?

i could look it up, i guess...|||The (+) goes on the "outer" side of the join, i.e.

t1.id = t2.id (+)
and t1.starttime < t2.starttime (+)

compare two tables

Hi all,
We have one master table with all records of the second table but the second
table doesn't contains all the records of the master table.
Like:
Master Table
ID Value
1 A
1 B
1 C
1 D
2 A
2 B
Second Table
ID Value
1 A
1 D
2 A
How can i compare so I can have this result for 2 million records?
1 B
1 C
2 B
Tks in advance
JFBSELECT MasterTable.Id, MasterTable.Value, SecondTable.Id
FROM MasterTable
LEFT OUTER JOIN SecondTable
ON MasterTable.Id = SecondTable.Id
AND MasterTable.Value = SecondTable.Value
WHERE SecondTable.ID IS NULL
Should display all the records from the Master Table that do not have a
match in the SecondTable.
"JFB" <help@.jfb.com> wrote in message
news:eQhPgH56FHA.3388@.TK2MSFTNGP11.phx.gbl...
> Hi all,
> We have one master table with all records of the second table but the
> second table doesn't contains all the records of the master table.
> Like:
> Master Table
> ID Value
> 1 A
> 1 B
> 1 C
> 1 D
> 2 A
> 2 B
> Second Table
> ID Value
> 1 A
> 1 D
> 2 A
> How can i compare so I can have this result for 2 million records?
> 1 B
> 1 C
> 2 B
> Tks in advance
> JFB
>|||Great Bill... tks for you help :)
Rgds
JFB
"Bill Edwards" <billedwards@.msn.com> wrote in message
news:u8sxPT56FHA.3648@.tk2msftngp13.phx.gbl...
> SELECT MasterTable.Id, MasterTable.Value, SecondTable.Id
> FROM MasterTable
> LEFT OUTER JOIN SecondTable
> ON MasterTable.Id = SecondTable.Id
> AND MasterTable.Value = SecondTable.Value
> WHERE SecondTable.ID IS NULL
> Should display all the records from the Master Table that do not have a
> match in the SecondTable.
> "JFB" <help@.jfb.com> wrote in message
> news:eQhPgH56FHA.3388@.TK2MSFTNGP11.phx.gbl...
>sqlsql

Monday, March 19, 2012

Compare Tables?

Hello. I have two copies of a database (one older, one newer). I
would like to compare them and take the records that do not appear in
both dbs and copy them to the newer one.
As much as I would like to manually go through, row by row, is there
an easier way'
Using:
- SQL 7
- Win NT
Many thanks!
JDThere's a 3rd party product called SQLCompare...
--
HTH
Ryan Waight, MCDBA, MCSE
"JD" <whatchoogot@.hotmail.com> wrote in message
news:b809817a.0311120722.5bcbac2f@.posting.google.com...
> Hello. I have two copies of a database (one older, one newer). I
> would like to compare them and take the records that do not appear in
> both dbs and copy them to the newer one.
> As much as I would like to manually go through, row by row, is there
> an easier way'
> Using:
> - SQL 7
> - Win NT
> Many thanks!
> JD|||JD,
I have used this product it great but becareful because
it will lock the table during comparing. It best that
you don't do this in production server.
Take Care,
Rachan
>--Original Message--
>There's a 3rd party product called SQLCompare...
>--
>HTH
>Ryan Waight, MCDBA, MCSE
>"JD" <whatchoogot@.hotmail.com> wrote in message
>news:b809817a.0311120722.5bcbac2f@.posting.google.com...
>> Hello. I have two copies of a database (one older,
one newer). I
>> would like to compare them and take the records that
do not appear in
>> both dbs and copy them to the newer one.
>> As much as I would like to manually go through, row by
row, is there
>> an easier way'
>> Using:
>> - SQL 7
>> - Win NT
>> Many thanks!
>> JD
>
>.
>|||Also a 3rd party tool called DB Ghost at www.dbghost.com
Thanks,
Darren Fuller MCSE
>--Original Message--
>Hello. I have two copies of a database (one older, one
newer). I
>would like to compare them and take the records that do
not appear in
>both dbs and copy them to the newer one.
>As much as I would like to manually go through, row by
row, is there
>an easier way'
>Using:
>- SQL 7
>- Win NT
>Many thanks!
>JD
>.
>