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 2005 Forums
 Transact-SQL (2005)
 a simple if statement that doesn't work

Author  Topic 

anj755
Starting Member

8 Posts

Posted - 2007-02-14 : 15:21:11

if exists (select AiD from A where A.AiD = inserted.Aid)


I am writing this statement on a trigger sp, where I have 'inserted' table
May be it is very trivial but I can't seem to reason why this statement is returning a error

Msg 102, Level 15, State 1, Line 1
Incorrect syntax near ')'.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-02-14 : 15:22:54
if exists (select AiD from A inner join inserted on A.AiD = inserted.Aid)

Tara Kizer
Go to Top of Page

anj755
Starting Member

8 Posts

Posted - 2007-02-14 : 15:39:29
if exists (select AiD from A inner join inserted on A.AiD = inserted.AiD)

still the same error

this is all I have written in my codes

create trigger tableD_Insert on tableD
instead of insert
as
if exists (select AiD from A inner join inserted on A.AiD = inserted.AiD)

Table A is a valid table in the database
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-02-14 : 16:13:21
Well you need more code after the IF statement. You don't have a single line after the ).

But if this is for a trigger (I didn't want to assume trigger in case inserted was an actual user table name), then you should not use IF to check for rows. You should use IF @@ROWCOUNT instead.

Tara Kizer
Go to Top of Page

anj755
Starting Member

8 Posts

Posted - 2007-02-14 : 16:31:28
You are right, the error I was getting had nothing to do with the if statement. I figured it out. I am sorry for wasting everyone's time, you know how it is, you are determined to finish few things before the end of day, and even the smallest error gets on your nerve.
Go to Top of Page
   

- Advertisement -