348 Part I EXAM PREPARATION continued BEGIN UPDATE

348 Part I EXAM PREPARATION continued BEGIN UPDATE mytable SET emptype = manager WHERE name = . fred PRINT There were rows changed END ELSE PRINT There were no rows changed The EXISTS() function returns true if even one row in the enclosed select statement returns rows. This type of logic provides a lot of flexibility in script writing by making it easy to check that data meets certain criteria before you perform an insert. IF constructs can also be nested in a couple of different ways. First, you can create scripts that chain together several constructs: IF (SELECT emptype FROM mytable WHERE name = fred ) <> . manager BEGIN UPDATE mytable SET emptype = manager WHERE name = . fred PRINT There were rows changed END ELSE BEGIN IF (SELECT emptype FROM mytable WHERE name = wilma ) .<> manager BEGIN UPDATE mytable SET emptype = manager .WHERE name = wilma END END Notice two significant things in that example. First, the statement has a fallback, if fred is already a manager, it sets wilma to manager also. An ELSE statement could be put into the bottom IF statement to print out the No records changed messages also. Another thing to notice is that the BEGIN-END pairs in the ELSE clause of the construct are optional and, in this case, not required. It could be rewritten like this: IF (SELECT emptype FROM mytable WHERE name = fred ) <> . manager BEGIN UPDATE mytable SET emptype = manager WHERE name = . fred PRINT There were rows changed END ELSE IF (SELECT emptype FROM mytable WHERE name = wilma ) .<> manager UPDATE mytable SET emptype = manager .WHERE name = wilma

If you looking for unlimited one inclusive web hosting plan please check unlimited web hosting website.

Comments are closed.