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 |
sqlserverdeveloper
Posting Yak Master
243 Posts |
Posted - 2008-08-27 : 17:10:50
|
Here is the below SQL:While ....BeginIf Exists()Begin Insert into Table1 ....EndElse --First Else PartPrint 'Entering into First Else..'IF NOT Exists()Begin Insert into Table2...EndElse --Second Else PartBegin Print 'Entering into Second Else..'Insert into third table ..EndBased 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 PartPrint 'Entering into First Else..'IF NOT Exists()Begin Insert into Table2...EndIf 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 |
 |
|
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 BeginInsert that order into DuplicateOrders tableEndElse --Not existing in orders table, new orderCheck if the representative who booked the order is in representatives tableIf representative not existing in the representatives tableBeginInsert that order into the ExceptionsOrder tableEndElse --that order is booked by a valid representative, so insert that order into Orders tableBeginInsert that order into Orders tableEnd |
 |
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2008-08-28 : 00:22:35
|
did you try what I suggested? elsasoft.org |
 |
|
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. |
 |
|
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 |
 |
|
|
|
|