SQL Dynamic Update table field incoming fields may be empty

Source: Internet
Author: User

Tip: The project group has a basic information field to modify the product but sometimes the incoming field may or may not be empty dynamically modify the fields in the table.

1  Use [betaproductmarket_db]2 GO3 IF(EXISTS(SELECT *  fromDbo.sysobjectsWHEREId=object_id(N'[dbo]. [Usp_saveproductbaseinfo]') and ObjectProperty(ID, N'isprocedure')= 1))4 BEGIN5     DROP PROCEDURE [dbo]. Usp_saveproductbaseinfo6 END7 GO8 9 /*Ten Author: Roni One function: Modify product basic information A creation time: 2016-5-24 -  - Summary: the      - */ -  - CREATE PROCEDURE [dbo]. Usp_saveproductbaseinfo +  -     @ProductID INT, +     @ProductType TINYINT=0, A     @ProductName VARCHAR( $)=NULL , at     @RecommendIndex TINYINT=0     , -     @Issuer VARCHAR( $)=NULL, -     @Period TINYINT=0    , -     @Movement VARCHAR( -)=NULL , -     @InvestmentDirection TINYINT=7, -     @YieldsFixed   DECIMAL( -,4)=0    , in     @YieldsFloat   DECIMAL( -,4)=0     , -     @YieldsType     TINYINT=0    , to     @Amount    DECIMAL( -,4)=0      +   -  as the  * BEGIN $ Panax Notoginseng      - UPDATEtb_product the SETUpdateTime=GETDATE(), +ProductName=  Case  when @ProductName  is NULL  ThenTb_product.productnameELSE @ProductName END , AProductType=  Case  when @ProductType=0  ThenTb_product.producttypeELSE @ProductType END   , theRecommendindex=  Case  when @RecommendIndex =0  ThenTb_product.recommendindexELSE @ProductType END     , +Issuer=  Case  when @Issuer  is NULL  ThenTb_product.issuerELSE @Issuer END , -Period=  Case  when @Period=0  ThenTb_product.periodELSE @Period END   , $Movement=  Case  when @Movement  is NULL  ThenTb_product.movementELSE @Movement END , $Investmentdirection=  Case  when @InvestmentDirection=7  ThenTb_product.investmentdirectionELSE @InvestmentDirection END   , -Yieldsfixed=  Case  when @YieldsFixed=0  ThenTb_product.yieldsfixedELSE @YieldsFixed END   , -Yieldsfloat=  Case  when @YieldsFloat=0  ThenTb_product.yieldsfloatELSE @YieldsFloat END   , theYieldstype=  Case  when @YieldsType=0  ThenTb_product.yieldstypeELSE @YieldsType END   , -Amount=  Case  when @Amount=0  ThenTb_product.amountELSE @Amount END   Wuyi WHEREProductID= @ProductID the  -  Wu  -  About        $  - END

SQL Dynamic Update table field incoming fields may be empty

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.