Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Building UPDATE dynamically
Message
 
 
À
18/03/2014 14:10:58
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Versions des environnements
SQL Server:
SQL Server 2012
Application:
Web
Divers
Thread ID:
01596792
Message ID:
01596846
Vues:
63
Every time I see something like that I have a feeling that it's not a right way accomplish the goal.

>I am trying to build a dynamic UPDATE statement in a SQL Server Stored Procedure.
>
>I pass to the SQL Stored procedure an XML string (@XmlDocWo) that has field name/value pairs. Then I extract a value for a field from the XML as following:
>
>
>SELECT @Fld1Value = [Fld FldName].value('.','char(10)') FROM @XmlDocWo.nodes('/TABLE_NAME/Fld') Fld([Fld FldName]) 
>	 WHERE [Fld FldName].value('@name','varchar(20)') = 'FLD1NAME'
>
>SELECT @ Fld2Value = [Fld FldName].value('.','char(10)') FROM @XmlDocWo.nodes('/TABLE_NAME/Fld') Fld([Fld FldName]) 
>	 WHERE [Fld FldName].value('@name','varchar(20)') = 'FLD2NAME'
>
>
>Then the Update command would be as follows:
>
>
>UPDATE MyTable SET FLD1NAME = @Fld1Value, FLD2NAME = @Fld2Value where PK_FLD = @PkFldValue
>
>
>The above expression would have more than 2 fields, of course. And I am looking for the way to eliminate one or some fields if they are not included in XML. For example, if XML string does not have value for FLD2NAME the UPDATE expression would be:
>
>
>UPDATE MyTable SET FLD1NAME = @Fld1Value where PK_FLD = @PkFldValue
>
>
>How would you suggest I go about it?
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform