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)
 t-sql question

Author  Topic 

sqlserverdeveloper
Posting Yak Master

243 Posts

Posted - 2008-08-27 : 17:10:50
Here is the below SQL:

While ....
Begin
If Exists()
Begin
Insert into Table1 ....
End

Else --First Else Part

Print 'Entering into First Else..'
IF NOT Exists()
Begin
Insert into Table2...
End

Else --Second Else Part
Begin
Print 'Entering into Second Else..'
Insert into third table ..
End

Based on the valid conditions, it enters into the first else part only if the Print statement is present. The same
issue with the second else part too.

Else --First Else Part
Print 'Entering into First Else..'
IF NOT Exists()
Begin
Insert into Table2...
End

If I remove the Print statement from the above SQL it does'nt enter in the Else part at all, even after valid conditions.
Please let me know your thoughts. Thanks much!!

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2008-08-27 : 19:37:15
put the PRINTs after the BEGINs, not between ELSE and IF.


elsasoft.org
Go to Top of Page

sqlserverdeveloper
Posting Yak Master

243 Posts

Posted - 2008-08-27 : 22:21:47
Thanks for the reply.
This is what I am trying to do:
IF order EXISTS in the orders table
Begin
Insert that order into DuplicateOrders table
End
Else --Not existing in orders table, new order
Check if the representative who booked the order is in representatives table
If representative not existing in the representatives table
Begin
Insert that order into the ExceptionsOrder table
End
Else --that order is booked by a valid representative, so insert that order into Orders table
Begin
Insert that order into Orders table
End
Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2008-08-28 : 00:22:35
did you try what I suggested?


elsasoft.org
Go to Top of Page

sqlserverdeveloper
Posting Yak Master

243 Posts

Posted - 2008-08-28 : 09:24:54
quote:
Originally posted by jezemine

did you try what I suggested?


elsasoft.org


Yes, I tried it's not working.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-28 : 09:42:56
quote:
Originally posted by sqlserverdeveloper

quote:
Originally posted by jezemine

did you try what I suggested?


elsasoft.org


Yes, I tried it's not working.


give the full if else code and also some sample data so that we can try
Go to Top of Page
   

- Advertisement -