午夜国产狂喷潮在线观看|国产AⅤ精品一区二区久久|中文字幕AV中文字幕|国产看片高清在线

    sql清空表數(shù)據(jù)后重新添加數(shù)據(jù)存儲(chǔ)過程的示例
    來(lái)源:易賢網(wǎng) 閱讀:1564 次 日期:2014-05-12 14:36:52
    溫馨提示:易賢網(wǎng)小編為您整理了“sql清空表數(shù)據(jù)后重新添加數(shù)據(jù)存儲(chǔ)過程的示例”,方便廣大網(wǎng)友查閱!

    代碼如下:

    ALTER PROCEDURE [dbo].[sp_add_Jurisdiction]

    @CTableName varchar(20), --當(dāng)前要?jiǎng)h除、新增的表

    @filedkeyValue varchar(20), --要?jiǎng)h除的字段值

    @filedName varchar(20), --要?jiǎng)h除的字段名

    @filedNameAdd1 varchar(20), --要新增的字段名1

    @filedNameAdd2 varchar(20), --要新增的字段名2

    @sql varchar(6000) --新增值字符串,如:25,30;25,31

    AS

    begin

    declare @strSQL_1 varchar(6000) -- 刪除

    declare @strSQL_2 varchar(6000) -- 新增

    BEGIN try

    BEGIN TRANSACTION

    set @strSQL_1 = 'delete from ['+@CTableName+'] where '+@filedName+' = '+@filedkeyValue+''

    exec(@strSQL_1)

    DECLARE @Run bit --繼續(xù)循環(huán)的標(biāo)志

    declare @dotIndex as int

    declare @doIndex as int

    declare @strValue1 as varchar(100)

    declare @strValue2 as varchar(100)

    declare @strText as varchar(100)

    declare @ReturnValue int

    set @Run = 1

    set @ReturnValue=0;

    while( @Run = 1)

    begin

    if(len(@sql)>0) --如果字符串還不為空,則進(jìn)行一下操作

    begin

    set @dotIndex=CharIndex(';',@sql)

    if(@dotIndex = 0) --判斷是否找到了';'符號(hào)

    begin

    set @doIndex=CharIndex(',',@sql)

    set @strValue1 = substring(@sql,1,@doIndex-1)

    set @strValue2 = substring(@sql,@doIndex+1,LEN(@sql))

    set @strSQL_2 = 'insert into ['+@CTableName+'] ('+@filedName+','+@filedNameAdd1+','+@filedNameAdd2+') values ('+@filedkeyValue+','+@strValue1+','+@strValue2+')'

    exec(@strSQL_2);

    set @ReturnValue=@ReturnValue+1;

    set @Run=0

    end;

    else

    begin

    set @strText = substring(@sql,1,@dotIndex-1) --截取','前的字符串

    set @sql=substring(@sql,@dotIndex+1,len(@sql)) --把字符串的長(zhǎng)度縮短至后一個(gè)

    set @doIndex=CharIndex(',',@strText)

    set @strValue1 = substring(@strText,1,@doIndex-1)

    set @strValue2 = substring(@strText,@doIndex+1,LEN(@strText))

    set @strSQL_2 = 'insert into ['+@CTableName+'] ('+@filedName+','+@filedNameAdd1+','+@filedNameAdd2+') values ('+@filedkeyValue+','+@strValue1+','+@strValue2+')'

    exec(@strSQL_2)

    set @ReturnValue=@ReturnValue+1;

    end

    end

    else

    begin

    set @Run=0

    set @ReturnValue=@ReturnValue+1;

    end

    end

    Commit Transaction

    return @ReturnValue;

    end try

    begin catch

    set @ReturnValue=0;

    Rollback Transaction

    return @ReturnValue;

    end catch

    end

    更多信息請(qǐng)查看IT技術(shù)專欄

    更多信息請(qǐng)查看數(shù)據(jù)庫(kù)
    由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

    2025國(guó)考·省考課程試聽報(bào)名

    • 報(bào)班類型
    • 姓名
    • 手機(jī)號(hào)
    • 驗(yàn)證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn) | 投訴建議
    工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
    云南網(wǎng)警備案專用圖標(biāo)
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
    云南網(wǎng)警報(bào)警專用圖標(biāo)