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)
 simple insert?

Author  Topic 

mikedu
Starting Member

9 Posts

Posted - 2012-06-08 : 15:13:12
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

38200 Posts

Posted - 2012-06-08 : 15:16:21
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

38200 Posts

Posted - 2012-06-08 : 15:16:54
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 - 2012-06-08 : 15:40:37
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

38200 Posts

Posted - 2012-06-08 : 15:42:42
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
   

- Advertisement -