Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
To create History table to record changes in fields
Message
 
 
À
13/07/2006 21:53:21
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Versions des environnements
SQL Server:
SQL Server 2000
Divers
Thread ID:
01135878
Message ID:
01136457
Vues:
16
Hi Kevin,

Thanks for the reply.

I am looking for 7 fields for update, I put the values in variables depending on which field or fields are updated like
if update(ICN)
set @a = 1
if update(processid)
set @b = 2
if update(provstatus)
set @c = 4

Set @d = @a + @b + @c

Now @d can tell if one field or two fields or all three fields or 1st and 3rd field etc. are updated. To capture all scenerios, I have written like ----
if (@d == 1)
Begin
Set @CColumn_name = 'ICN'
exec dbo.Update_Hist @CColumn_name, @dLastUpdate
End
else
if (@d = 2 )
Begin
Set @CColumn_name = 'processid'
exec Update_Hist @CColumn_name, @dLastUpdate
End
else
if (@d = 4)
Begin
Set @CColumn_name = 'provstatus'
exec Update_Hist @CColumn_name, @dLastUpdate
End
if (@d = 3)
Begin
Set @CColumn_name = 'ICN'
exec Update_Hist @CColumn_name, @dLastUpdate
Set @CColumn_name = 'processid'
exec Update_Hist @CColumn_name, @dLastUpdate
End
----------so instead of writing the insert query for each scenerio, I have written a common stored procedure out side which accepts variables depending on the value of @d. Since inserted and deleted tables are not known in the Update_Hist stored procedure, I can pass the old and new value from these temp tables also as parameters in the stored procedure.

Why I am doing it like this because I am not good in writing scripts.

Regards
bharat
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform