Link to home
Start Free TrialLog in
Avatar of Amour22015
Amour22015

asked on

SQL Server 2008 R2 - How to update a record field/colum using @SQL

Hi experts,

I am executing a stored procedure using SSIS and am passing one parameter to that SP

The passing of the parameter works fine.

I just need to get this part to work:
    PRINT 'STARTING UPDATE OF CLAIM RECORDS IN DATABASE_TABLES: ' + @TBLNM
      SET @rc = 1
      WHILE @rc > 0
      BEGIN
      SELECT @sql =  'IF OBJECT_ID (''dbo.' + @TBLNM + ''') IS NULL
      UPDATE DATABASE_TABLES set TBL_STAT = ' +'DELETED' + 'WHERE TBL_NM =' + @TBL_NM +' and TBL_STAT =' + 'PURGE_ELIG'
          exec sp_executesql @sql;
                 
         
                  SET @rc = @@ROWCOUNT
      END;
      PRINT 'ENDING UPDATE OF CLAIM RECORDS IN DATABASE_TABLES: ' + @TBLNM

The reason why I am using a dynamic query is because of the parameter "@TBLNM"

I want to make sure the table that is indicated by the @TBLNM is NOT there (Has already been deleted) then to mark it in the record of DATABASE_TABLES as 'DELETED' in the correct field "TBL_STAT "

I know I am close to solving and just wanted an expert touch to finish it off...

Please help and thanks
ASKER CERTIFIED SOLUTION
Avatar of John_Vidmar
John_Vidmar
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Amour22015
Amour22015

ASKER

Great thanks, that worked