Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Can I use an IF
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Titre:
Divers
Thread ID:
00761098
Message ID:
00761879
Vues:
31
>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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform