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.
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 2Incorrect 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 |
|
|
danasegarane76
Posting Yak Master
242 Posts |
Posted - 2008-10-16 : 07:25:17
|
Thanks for the Reply Charlie. I was trying this likeIF 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 againDana |
|
|
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 varcharset @jaar='2008'IF NOT EXISTS (Select jaar from soljaren where jaar=@jaar) begin INSERT INTO soljaren (jaar) values(@jaar) end |
|
|
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 likeIF 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 againDana
Why did you remove the column list in the INSERT statement?MadhivananFailing to plan is Planning to fail |
|
|
|
|
|