Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can I use an IF
Message
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Title:
Miscellaneous
Thread ID:
00761098
Message ID:
00761879
Views:
32
>I want to write a stored procedure, and pass it several parameters. One of the parameters would be if it is an update or new record. Can I write a stored procedure that:
>
>if @tiAction=1
> * Code to Update
>else
> * Code to insert
>
>
>
>Thanks
>Kirk

Yes - but keep in mind only the very next line of code after the IF statement line will fire. If you want a section of code to be dependant on the IF statement you will need to use a BEGIN... END statement like this:

IF ((select cType from deleted where deleted.iOrder = iOrder) <> 'E')
BEGIN
UPDATE dbo.orders
SET tEdited = GETDATE()
WHERE iOrder IN (SELECT iOrder FROM inserted)
UPDATE dbo.customers
SET tEdited= GETDATE()
WHERE iCustomer IN (SELECT iCustomer FROM inserted)
END
Previous
Reply
Map
View

Click here to load this message in the networking platform