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
Microsoft SQL ServerMicrosoft SQL Server 2008SSISSQL

Avatar of undefined
Last Comment
Amour22015

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
John_Vidmar

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Amour22015

ASKER
Great thanks, that worked
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy