SET @DynamicSQL = 'UPDATE U SET U.ADDRESS1 = U.ADDRESS2, U.ADDRESS2 = NULL FROM USER U INNER JOIN EMPOYEE E ON E.USER_ID = U.USER_ID WHERE U.TYPE = ''' + @TYPE + ''''
EXEC(@DynamicSQL)
PRINT @DynamicSQL
I am creating the dynamic sql inside the stored procedure as shown above, Now when it executes in SP it prints correct sql i wanted, but on rows updated on EXEC are '0'. However when i try to execute the sql which is generated by printing the sql in SP, it shows me 150 rows updated.
Now what could be the reason that EXEC is not able to update the rows, and directly calling PRINTED sql does ?