SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 simple insert?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mikedu
Starting Member

9 Posts

Posted - 06/08/2012 :  15:13:12  Show Profile  Reply with Quote
I have (what should be) simple insert into an error table. If count's from two different tables don't match, I want to insert values. The top portion is fine but I am getting an error on my insert statement. ('incorrect syntax near where')

Any ideas?

declare @notes integer;
declare @sql integer;
set @notes = (select COUNT(*) from tblPG_Notes_Validation);
set @sql = (select COUNT(*) from tblPG_Sql_Validation);

INSERT INTO tblPG_Errors
VALUES (1, 'Total Count doesnt match', GETDATE())
where @notes <> @sql

tkizer
Almighty SQL Goddess

USA
35007 Posts

Posted - 06/08/2012 :  15:16:21  Show Profile  Visit tkizer's Homepage  Reply with Quote
IF @notes <> @sql
INSERT INTO tblPG_Errors
VALUES (1, 'Total Count doesnt match', GETDATE())

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

tkizer
Almighty SQL Goddess

USA
35007 Posts

Posted - 06/08/2012 :  15:16:54  Show Profile  Visit tkizer's Homepage  Reply with Quote
I would get rid of the variables though:

if (select COUNT(*) from tblPG_Notes_Validation) <> (select COUNT(*) from tblPG_Sql_Validation)
INSERT INTO tblPG_Errors
VALUES (1, 'Total Count doesnt match', GETDATE())

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

mikedu
Starting Member

9 Posts

Posted - 06/08/2012 :  15:40:37  Show Profile  Reply with Quote
Thanks tara, the last 2nd option was exactly what I was looking for but couldn't think of....must be a friday afternoon thing...

Go to Top of Page

tkizer
Almighty SQL Goddess

USA
35007 Posts

Posted - 06/08/2012 :  15:42:42  Show Profile  Visit tkizer's Homepage  Reply with Quote
You're welcome, glad to help.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000