Update Query has me confused

  • I have the following SP that runs daily.

    ALTER PROCEDURE [dbo].[usp_token_disable]

    AS

    BEGIN

    set nocount on

    declare @tbl1 table(outrec varchar(max))

    update tbl_token_replace set Disabled_Date=getdate(),disabled_code = case when (getdate() >= dateadd(dd,14,email_2_sent) and mac_confirm is null) then 'No_Verify' else

    'No_use'

    end

    output 'disable_token,' + inserted.chdefaultlogin + ',' + old.chserialnum as ourrec into @tbl1

    from tbl_token_replace

    inner join tbl_token_list_orig old on old.pk_token = org_chserialnum

    inner join sdtoken tok on tok.chserialnum = old.chserialnum and benabled = 'Yes'

    where (datediff(dd,email_2_sent,getdate()) >= 14 and mac_confirm is null) or (datediff(dd,email_3_sent,getdate()) >= 14 and replacement_status <> 1)

    select outrec from @tbl1

    end

    I'm geting 'No_Use' for all of the codes. If I run the following query right after the one above I 'fix' the column.

    update tbl_token_replace set Disabled_Date=getdate(),disabled_code = case when (getdate() >= dateadd(dd,14,email_2_sent) and mac_confirm is null) then 'No_Verify' else

    'No_use'

    end

    from tbl_token_replace

    inner join tbl_token_list_orig old on old.pk_token = org_chserialnum

    inner join sdtoken tok on tok.chserialnum = old.chserialnum and benabled = 'Yes'

    where (datediff(dd,email_2_sent,getdate()) >= 14 and mac_confirm is null) or (datediff(dd,email_3_sent,getdate()) >= 14 and replacement_status <> 1)

    They are the same except for the output.

  • Hit post too soon?

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • I did indeed! 🙂 Misfire.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply