SQL gets a field based on specified criteria bulk fetch data into another table fields

Source: Internet
Author: User

/** * * * object:storedprocedure [dbo].    [Getsplitvalue] Script date:03/13/2016 13:58:12 * * * * **/SETAnsi_nulls onGOSETQuoted_identifier onGO  ALTER PROCEDURE [dbo].[Getsplitvalue]  as        --Define get GUID    DECLARE @NEWID NVARCHAR( -)    SET @NEWID= REPLACE(NEWID(),'-',"')         --determine if the temporary table data exists and delete the temporary table if it existsif object_id('tempdb: # #project') is  not NULL        DROP TABLE# #projectif object_id('tempdb: # #projectA') is  not NULL        DROP TABLE# #projectA--Get data source information    SELECTId,guige,documentno,orderno,wlno,color,isfenma into# #project fromtb_flchukumxSELECTGuige,documentno,orderno,wlno,color,isfenma into# #projectA fromTb_flkucunWHEREOpttype='Pick Material'    --Defining Variables    DECLARE @id INT,@GuiGe NVARCHAR( -)    DECLARE  @DocumentNO NVARCHAR( -),@OrderNO NVARCHAR( -),@WLNO NVARCHAR( -),@Color NVARCHAR( -),@ISFenMa NVARCHAR( -)    DECLARE @sql NVARCHAR(Max)        SELECT @id = MIN(ID) from# #project while @id  is  not NULL BEGIN                    SELECT                @GuiGe=ISNULL(Guige,"'),@DocumentNO=Documentno,@OrderNO=OrderNo,@WLNO=Wlno,@Color=Color,@ISFenMa=Isfenma from# #projectWHEREId=@id                     --Defining Variables                     DECLARE @line INT =0                     SELECT @line=COUNT(0) from# #projectAWHEREDocumentno=@DocumentNO  andOrderNo=@OrderNO  andWlno=@WLNO  andColor=@Color  andIsfenma=@ISFenMa                                           --Data modification operation if data is queried                     IF @line >0  BEGIN                           SET @sql ='Update Tb_flkucun Set guige=" "+@GuiGe+" "where documentno=" "+@DocumentNO+" "and orderno=" "+@OrderNO+" "and wlno=" "+@WLNO+" "and color=" "+@Color+" "and isfenma=" "+@ISFenMa+" "and opttype="'Pick Material"' '                         PRINT @sql                        --EXEC (@sql)                      END                           SELECT @id = MIN(ID) fromdbo.# #projectWHEREId>@id           END                                                                                   --determine if the temporary table data exists and delete the temporary table if it exists    if object_id('tempdb: # #project') is  not NULL        DROP TABLE# #projectif object_id('tempdb: # #projectA') is  not NULL        DROP TABLE# #projectA

SQL gets a field based on specified criteria bulk fetch data into another table field

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.