Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
VB, C#, and VFP data handling examples
Message
De
27/04/2007 15:59:11
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, États-Unis
 
 
À
27/04/2007 15:44:23
Information générale
Forum:
Visual FoxPro
Catégorie:
Visual FoxPro et .NET
Divers
Thread ID:
01215120
Message ID:
01220594
Vues:
34
>Hey, Mike,
>
>In the UPDATE sproc, I do the following...
>
>
>@PrimKey int, @ParmCol1 varchar(50) = null, @ParmCool2 varchar(50) = null, etc.
>
>And in the actual UPDATE statement in the sproc...
>
>
>UPDATE MyTable SET Col1 = COALESCE(@ParmCol1,Col1), Col2 = COALESCE(@ParmCol2, Col2) WHERE PrimKey = @PrimKey
>
>You can think of COALESCE as being similar to ISNULL, though the functions are 'slightly' different.
>
>So let's say I have a table with 10 columns. If I actually only pass 2 parameters, the other 8 that wind up being 'null' are just going to get set to themselves.
>
>This UPDATE proc can become the database 'API' for any process that needs to update the table. Even if someone writes a back-end job just to update 3 columns, all they have to do is use this, and only specify the columns as parameters that they need to update.
>
>I rarely use dynamic SQL.
>
>Hope that helps...
>
>Kevin

(I think you have a typo in your sig)

I think I understand how COALESCE works... I read a bit about it once. However, if your parm is NULL, does the update on the field actually take place? I don't know if I am explaining my question correctly, but say for example I have a trigger set on the Col1 field. An update procedure is run with a null @ParmCol1 value, therefore setting it back to the original value. Is the value reset, and would the trigger pick it up? Or is SQL smart enough to know not to do an actual update?
Very fitting: http://xkcd.com/386/
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform