Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Can I get a value in Update
Message
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01314836
Message ID:
01314842
Vues:
13
>Hi everybody,
>
>Is it possible to grab a value from the field in a record I'm updating in one statement?
>
>In other words:
>
>@declare PersonType char(1)
>update Registration set Approved = 1 where RegistrationID = @RegistrationID
>
>Can I get PersonType in the same statement or should I do a separate select statement?
>
>Thanks in advance.
>
>Ok, I found that I probably can use OUTPUT clause.
>
>1. I found that WHERE clause should follow the output (otherwise I was getting errors).
>
>2. This statement
>UPDATE Registration Set Approved = 1
>WHERE RegistrationID = 1
>
>Takes a very long time in the SSMS. The Registration table has 1482 records and 60 columns.

Ok, I can get values using

UPDATE Registration Set Approved = 1
output INSERTED.PersonType, p.PersonType
FROM Registration as r inner join PersonTypes as p on r.PersonType = p.LetterCode
WHERE RegistrationID = 1

But how can I now use these values in the following statements of my SP? In other words, I need different logic depending on PersonType (update different tables).
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform