Results 1 to 1 of 1

Thread: Update Issue

  1. #1
    Join Date
    Sep 2002
    Posts
    218

    Update Issue

    l have a situation where l have two columns one for the tablename and one for the
    idkey.'m trying to do an update on this table to set all the blank tabname fields = to the tablename above it
    if the one below is Null .ie Tablename 'ZA02300P' and idkey '31267' should set all
    the nulls on tabname where idkey in 31268,31269,31270 = 'ZA02300P'. l have 70 000 records


    this is my train of thought ... need some guidance


    Declare @sql nvarchar(100)
    Set @sql = N'Select ExtableName_1 ,idkey + 1 From test '

    EXECUTE sp_executesql @sql

    BEGIN
    Update test
    Set tablename = Extablename
    Where tablename IS NULL
    AND idkey = cast(idkey AS INT) + 1
    END

    Update Test
    Set tabname_1 =
    where tablename is Null or tablename = ''




    l have a situation where l have two columns one for the tablename and one for the
    idkey.'m trying to do an update on this table to set all the blank tabname fields = to the tablename above it
    if the one below is Null .ie Tablename 'ZA02300P' and idkey '31267' should set all
    the nulls on tabname where idkey in 31268,31269,31270 = 'ZA02300P'. l have 70 000 records


    ----------this is what l have
    If object_id('tempdb..#Test') Is not Null
    Drop table #Test
    Go

    Create Table #Test
    (
    tablename Varchar(30)
    ,DesiredResult Varchar(30)
    ,Idkey int identity(1,1)
    )

    Insert Into #Test (tablename,DesiredResult) Values ('ADNNAM11' ,'Ok')
    Insert Into #Test (tablename,DesiredResult) Values ('AH90000P','Ok' )
    Insert Into #Test (tablename,DesiredResult) Values ('AH90000P','Ok')
    Insert Into #Test (tablename,DesiredResult) Values ('AH90000P','Ok')
    Insert Into #Test (tablename,DesiredResult) Values ('ZA02300P','Ok')
    Insert Into #Test (tablename,DesiredResult) Values ('', 'Should be ZA02300P' )
    Insert Into #Test (tablename,DesiredResult) Values ('', 'Should be ZA02300P')
    Insert Into #Test (tablename,DesiredResult) Values ('', 'Should be ZA02300P')
    Insert Into #Test (tablename,DesiredResult) Values ('ZA02300PNA','correct')
    Insert Into #Test (tablename,DesiredResult) Values ('','Should be ZA02300PNA')
    Insert Into #Test (tablename,DesiredResult) Values ('','Should be ZA02300PNA')
    Insert Into #Test (tablename,DesiredResult) Values ('','Should be ZA02300PNA')
    Insert Into #Test (tablename,DesiredResult) Values ('ADNNAM11','Ok')
    Insert Into #Test (tablename,DesiredResult) Values ('ADNNAM11','Ok')
    Insert Into #Test (tablename,DesiredResult) Values ('ADNNAM11','Ok')
    Insert Into #Test (tablename,DesiredResult) Values ('ADNNAM11','Ok')

    Select * from #test



    this is my train of thought ... need some guidance


    Declare @sql nvarchar(100)
    Set @sql = N'Select tablename ,idkey + 1 From #test '

    EXECUTE sp_executesql @sql

    BEGIN
    Update #test
    Set tablename = tablename
    Where tablename IS NULL
    AND idkey = cast(idkey AS INT) + 1
    END
    Last edited by sleezy; 11-07-2003 at 04:51 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •