field check

  • At the Foxpro, it can controll with INDBC command which field be or not at a file.

    Like : (FoxPro)

    IF INDBC(_seek,"FIELD") = .F.

    ALTER TABLE mal ADD COLUMN ("d" + ALLTRIM(STR(mary))) i NULL

    ENDIF

    At the Ms-Sql2000 Stored procedure I did a sample as follow. And I had trouble :

    1- the row of "ALTER TABLE mal ADD @depo money null" it gives back syntax error for @depo

    2- How can I get(handle) a field be or not at a file.

    Note : I want to do this operations inside of the stored procedure.

    Thanks

    Sample code of SQL :

    USE foxsql

    DECLARE @depo nvarchar(9)

    DECLARE depo_hrk CURSOR FOR

    SELECT DISTINCT 'depo_' + cast(depo as nvarchar(4)) as depo FROM hrk ORDER BY depo

    OPEN depo_hrk

    FETCH NEXT FROM depo_hrk INTO @depo

    WHILE @@fetch_status = 0

    BEGIN

    ALTER TABLE mal ADD @depo money null

    FETCH NEXT FROM depo_hrk INTO @depo

    END

    CLOSE depo_hrk

    deallocate depo_hrk

  • "1- the row of "ALTER TABLE mal ADD @depo money null" it gives back syntax error for @depo"

    This is becuase you are trying to add a columnn from a variable name.

    Try:-

    DECLARE @depo nvarchar(9)

    DECLARE @STR nvarchar(255)

    select @depo = 'col'

    select @STR = 'ALTER TABLE mal ADD ' + @depo + ' money null'

    exec (@str)

    Regards,

    Andy Jones

    andyj93@hotmail.com

    .

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

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