473,434 Members | 1,528 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,434 software developers and data experts.

SQL Database comparison

347 100+
I have the following query:

Expand|Select|Wrap|Line Numbers
  1. SET QUOTED_IDENTIFIER ON 
  2. GO
  3. SET ANSI_NULLS ON 
  4. GO
  5.  
  6. ALTER  PROCEDURE YourProcedure AS
  7.  
  8. insert into msbtotal.dbo.newclients
  9. SELECT tcms_members.dbo.memberdata.* FROM tcms_members.dbo.memberdata left outer join 
  10. msbtotal.dbo.memberdata on tcms_members.dbo.memberdata.id = 
  11. msbtotal.dbo.memberdata.id where msbtotal.dbo.memberdata.id is
  12. null
  13. GO
  14. SET QUOTED_IDENTIFIER OFF 
  15. GO
  16. SET ANSI_NULLS ON 
  17. GO
  18.  
And what I'm trying to do is to compare two databases on the same server to see if any new data is entered into tcms_members.dbo.memberdata compared to msbtotal.dbo.memberdata and if so, the new data is written to a table (in the msbtotal database) called "newclients." The data is checked via the ID field and if there is any new data in the tcms_members.dbo.memberdata, it will be evident by there being a new ID number. The query runs fine and I tried adding "sample" data into the database to have it inserted into the new client table and that sample data wasnt added BUT I also didn't receive any errors. I can provide the sample data if necessary but I was wondering if anyone can see anything wrong with my query that may cause this? The server is a SQL 2000 server and I am running the query as the admin on the server, just as an fyi.

Thank you

Doug
Sep 20 '10 #1

✓ answered by dougancil

CK,

I created a new table (newclients2) and inserted the data. For whatever reason that worked. It seems that the table "newclients" had something wrong with it, but I've fixed that and it seems to work correctly.

Thanks for your help.

Doug

22 2141
gpl
152 100+
A quick debugging question - do you get any results when you run just the select statement ?
Sep 21 '10 #2
ck9663
2,878 Expert 2GB
And...

If it's a simple check of record existence, an EXISTS() function might be faster...

Happy Coding!!!

~~ CK
Sep 21 '10 #3
dougancil
347 100+
CK,

Does EXISTS work in SQL 2000? Also, I have ran just the select statement and it does in fact locate the "sample data."

Here's the error I get when I add the insert statement back into the query:

Server: Msg 208, Level 16, State 1, Procedure newcustomers, Line 4
Invalid object name 'msbtotal.dbo.members'.

I've checked all of the SP on this server and there is no procedure called "newcustomers." Can anyone offer any advice as to why my server is telling me that there's a procedure that doesnt really exist.

Thanks

Doug
Sep 22 '10 #4
gpl
152 100+
EXISTS is part of the basic SQL language, so yes it does work

You are trying to alter a procedure called members in the database msbtotal

as it doesnt exist, it cannot alter it -- look again at the code you have -- if you cannot see it, then post it for us to debug.

I suspect you have
Expand|Select|Wrap|Line Numbers
  1. ALTER  PROCEDURE msbtotal.dbo.members AS 
instead of
Expand|Select|Wrap|Line Numbers
  1. ALTER  PROCEDURE YourProcedure AS 
Sep 22 '10 #5
dougancil
347 100+
QPL ... the code that I posted on my first entry is straight from my sql server. Please notice line 6.

Expand|Select|Wrap|Line Numbers
  1. SET QUOTED_IDENTIFIER ON 
  2. GO
  3. SET ANSI_NULLS ON 
  4. GO
  5.  
  6. ALTER  PROCEDURE YourProcedure AS
  7.  
  8. insert into msbtotal.dbo.newclients
  9. SELECT tcms_members.dbo.memberdata.* FROM tcms_members.dbo.memberdata left outer join 
  10. msbtotal.dbo.memberdata on tcms_members.dbo.memberdata.id = 
  11. msbtotal.dbo.memberdata.id where msbtotal.dbo.memberdata.id is
  12. null
  13. GO
  14. SET QUOTED_IDENTIFIER OFF 
  15. GO
  16. SET ANSI_NULLS ON 
  17. GO
  18.  
Sep 22 '10 #6
ck9663
2,878 Expert 2GB
Your actual procedure name is YourProcedure ? Or you change it to newcustomers?

Fix that first and let's see...

~~ CK
Sep 22 '10 #7
dougancil
347 100+
The procedure is called YourProcedure. I don't have a stored procedure called newcustomers. I've searched the entire server and every database on that server. There is no procedure called newcustomers.
Sep 22 '10 #8
ck9663
2,878 Expert 2GB
Since you don't have a parameter, you may actually run this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT tcms_members.dbo.memberdata.* FROM tcms_members.dbo.memberdata left outer join 
  3. msbtotal.dbo.memberdata on tcms_members.dbo.memberdata.id = 
  4. msbtotal.dbo.memberdata.id where msbtotal.dbo.memberdata.id is
  5. null
  6.  
  7.  
from your Query window. See if it returns any record or gives an error.

~~ CK
Sep 22 '10 #9
dougancil
347 100+
Ck,

That does not give an error.
Sep 22 '10 #10
ck9663
2,878 Expert 2GB
Now try this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. ALTER  PROCEDURE YourProcedure 
  3. AS
  4.    SELECT tcms_members.dbo.memberdata.* FROM tcms_members.dbo.memberdata left outer join 
  5.    msbtotal.dbo.memberdata on tcms_members.dbo.memberdata.id = 
  6.    msbtotal.dbo.memberdata.id where msbtotal.dbo.memberdata.id is null
  7.  
  8.  
~~ CK
Sep 22 '10 #11
dougancil
347 100+
CK,

That ran fine with no errors.
Sep 22 '10 #12
ck9663
2,878 Expert 2GB
So, your proc has been created. Try running it.

Expand|Select|Wrap|Line Numbers
  1.  
  2. EXEC YourProcedure 
  3.  
  4.  
~~ CK
Sep 22 '10 #13
dougancil
347 100+
Ck,

That procedure did run now we just need the insert (or exist statement)
Sep 22 '10 #14
ck9663
2,878 Expert 2GB
One at a time, we're trying to isolate your problem...

Now, try to put the insert command...

Expand|Select|Wrap|Line Numbers
  1.  
  2. ALTER  PROCEDURE YourProcedure 
  3. AS
  4.    insert into msbtotal.dbo.newclients
  5.    SELECT tcms_members.dbo.memberdata.* FROM tcms_members.dbo.memberdata left outer join 
  6.    msbtotal.dbo.memberdata on tcms_members.dbo.memberdata.id = 
  7.    msbtotal.dbo.memberdata.id where msbtotal.dbo.memberdata.id is null      
  8.  
  9.  
Then run your proc...


~~ CK
Sep 22 '10 #15
dougancil
347 100+
CK,

here's the error when I run my proc:

Server: Msg 208, Level 16, State 1, Procedure newcustomers, Line 4
Invalid object name 'msbtotal.dbo.members'.
Sep 22 '10 #16
ck9663
2,878 Expert 2GB
Did you run it this way:

Expand|Select|Wrap|Line Numbers
  1.  
  2. EXEC YourProcedure 
  3.  
  4.  
Sep 22 '10 #17
dougancil
347 100+
I did. Just like that.
Sep 22 '10 #18
ck9663
2,878 Expert 2GB
And you run it in a new query window, not being called inside another proc? Are you in the same DB? Are you calling any other proc? What version of ms sql server are you using?

~~ CK
Sep 22 '10 #19
dougancil
347 100+
Nope, the query is ran in a new query window. I am in the same db. I am not calling any other proc and this is running on a SQL 2000 server.
Sep 22 '10 #20
ck9663
2,878 Expert 2GB
The only remaining thing that I can think of is to list the column names that you are populating on the INSERT clause and the corresponding column name you are trying to insert to the table on the SELECT clause.

You might also want to create a copy of newclients table with a different name and insert it to that table instead.

Are you using any CALCULATED columns? Functions? Triggers? Constraint? etc?

~~ CK
Sep 22 '10 #21
dougancil
347 100+
I can try to create a new table and insert it into that but in answer to your other question, I'm not using any other triggers, or constraints or any calculations.

Doug
Sep 22 '10 #22
dougancil
347 100+
CK,

I created a new table (newclients2) and inserted the data. For whatever reason that worked. It seems that the table "newclients" had something wrong with it, but I've fixed that and it seems to work correctly.

Thanks for your help.

Doug
Sep 22 '10 #23

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: democratix | last post by:
Hi, I've only got a couple years experience developing for Access but have recently been experimenting with HTML/javascript for gui and client-side scripting, mysql for database and php for...
4
by: Susan Lam | last post by:
I am looking for some papers/information that compare relational databases such as oracle, mysql, sql server etc. I am particularly interested in their features such as locking mechanisms,...
0
by: bettervssremoting | last post by:
To view the full article, please visit http://www.BetterVssRemoting.com Better VSS Remote Access Tool This article makes a detailed comparison among SourceAnyWhere, SourceOffSite, VSS...
5
by: Stuart Ferguson | last post by:
I am currently in the process of making changes to an application using a SQL Server database and have made changes to a development copy of the live database which includes changing and adding...
3
by: aaj | last post by:
Hi all I have Aceess 2000 front end linking to SQLServer 2000 BE. While developing the backend I work on an offline database. When happy I update the live one. Any changes I've made to the...
5
by: mayamorning123 | last post by:
A comparison among six VSS remote tools including SourceOffSite , SourceAnyWhere, VSS Connect, SourceXT, VSS Remoting, VSS.NET To view the full article, please visit...
0
by: bettervssremoting | last post by:
To view the full article, please visit http://www.BetterVssRemoting.com Better VSS Remote Access Tool This article makes a detailed comparison among SourceAnyWhere, SourceOffSite, VSS...
7
by: bcutting | last post by:
I am looking for a way to take a large number of images and find matches among them. These images may not be exact replicas. Images may have been resized, cropped, faded, color corrected, etc. ...
7
by: darrel | last post by:
Hello vb masters, am having difficulty in comparing database through my visual basic program, i'am using access database and sql statement, i'am doing a time scheduling system, so one of the thing...
1
by: AllBeagle | last post by:
Hello Everyone, I'm trying to build a web-based application for a client of mine and I keep finding holes in my design, so I could use some guidance if anyone has any to offer. Let me try to...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.