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 2000 Forums
 Transact-SQL (2000)
 Conditional Insert

Author  Topic 

danasegarane76
Posting Yak Master

242 Posts

Posted - 2008-10-16 : 06:12:34
Insert into soljaren values('2008')
Where Not Exists
(Select jaar from soljaren where jaar='2008')

While Running i getting syntax error..

Could some one help ?




Server: Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'Where'.

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2008-10-16 : 06:40:38
Your logic doesn't make sense.

Are you maybe looking for this?


IF NOT EXISTS (Select jaar from soljaren where jaar='2008')
INSERT INTO soljaren (jaar) values('2008')


-------------
Charlie
Go to Top of Page

danasegarane76
Posting Yak Master

242 Posts

Posted - 2008-10-16 : 07:25:17
Thanks for the Reply Charlie. I was trying this like

IF NOT EXISTS (Select jaar from soljaren where jaar='2008')
INSERT INTO soljaren values('2008')

But It was throwing the same. Now it works. I dont know what i did wrong..

Thanks once again
Dana
Go to Top of Page

wormz666
Posting Yak Master

110 Posts

Posted - 2008-10-16 : 10:04:03
you need to specify which field in the soljaren table will you insert

declare @jaar varchar
set @jaar='2008'
IF NOT EXISTS (Select jaar from soljaren where jaar=@jaar)
begin
INSERT INTO soljaren (jaar) values(@jaar)
end
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-10-16 : 10:17:46
quote:
Originally posted by danasegarane76

Thanks for the Reply Charlie. I was trying this like

IF NOT EXISTS (Select jaar from soljaren where jaar='2008')
INSERT INTO soljaren values('2008')

But It was throwing the same. Now it works. I dont know what i did wrong..

Thanks once again
Dana


Why did you remove the column list in the INSERT statement?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -