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)
 Incorrect syntax near ELSE

Author  Topic 

zhshqzyc
Posting Yak Master

240 Posts

Posted - 2008-07-23 : 12:14:02
[code]IF NOT EXISTS (SELECT A FROM X WHERE A= '444444')
BEGIN
IF NOT EXISTS (SELECT 1 FROM Y WHERE U='888888')
INSERT INTO Y (U,V,W,P,T)
VALUES('888888','-1','-1','0','249.5')
END
ELSE
BEGIN
IF EXISTS (SELECT 1 FROM Y WHERE U='888888')
INSERT INTO Y (U,V,W,P,T)
VALUES('888888','-1','-1','0','249.5')
END[/code]
Thanks for your help.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-23 : 12:50:56
i dont think error is in posted code. can you post you full code please?
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-07-23 : 13:03:57
You want the insert ONLY to happen if

1) Table X AND Table Y does have record
2) Table X AND Table Y doesn't have record



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

zhshqzyc
Posting Yak Master

240 Posts

Posted - 2008-07-23 : 13:12:40
quote:
Originally posted by Peso

You want the insert ONLY to happen if

1) Table X AND Table Y does have record
2) Table X AND Table Y doesn't have record



E 12°55'05.25"
N 56°04'39.16"



Yeah.
Go to Top of Page

zhshqzyc
Posting Yak Master

240 Posts

Posted - 2008-07-23 : 13:12:40
quote:
Originally posted by Peso

You want the insert ONLY to happen if

1) Table X AND Table Y does have record
2) Table X AND Table Y doesn't have record



E 12°55'05.25"
N 56°04'39.16"



Yeah.
Go to Top of Page
   

- Advertisement -