0

I have a temporary table that I want to perform some data manipulation on, and then write back to the originating table. However, as a first step I would like to compare the original data side by side with the altered data.

Given the query below, how can I write to the modified data to the a new column in the temporary table so that I can compare side by side? I'm using SQL Server 2008.


UPDATE #TempCustomControls
SET ConfigValue =
CASE 
    WHEN ConfigValue like '%GetPersonProperty%$PersonID$%'
    THEN 'PersonLogic.GetPersonProperty($PersonID$, ' + RIGHT(ConfigValue, charindex(',', REVERSE(ConfigValue))-1) + ')'

    WHEN ConfigValue like '%GetProfileProperty%$PersonID$%'
    THEN 'PersonLogic.GetPersonProperty($PersonID$, ' + RIGHT(ConfigValue, charindex(',', REVERSE(ConfigValue))-1) + ')'

    WHEN ConfigValue like '%GetProfileProperty%GetJobCreatedByPerson%$JobID$%'
    THEN 'PersonLogic.GetPersonPropertyFromJobID($JobId$, ' + RIGHT(ConfigValue, charindex(',', REVERSE(ConfigValue))-1) + ')'
ELSE
    ConfigValue 
END

1 Answer 1

1

Add a new column in temp table and update the new column instead of ConfigValue.

Alter table #TempCustomControls add new_value varchar(100)

UPDATE #TempCustomControls
SET new_value =
CASE 
    WHEN ConfigValue like '%GetPersonProperty%$PersonID$%'
    THEN 'PersonLogic.GetPersonProperty($PersonID$, ' + RIGHT(ConfigValue, charindex(',', REVERSE(ConfigValue))-1) + ')'

    WHEN ConfigValue like '%GetProfileProperty%$PersonID$%'
    THEN 'PersonLogic.GetPersonProperty($PersonID$, ' + RIGHT(ConfigValue, charindex(',', REVERSE(ConfigValue))-1) + ')'

    WHEN ConfigValue like '%GetProfileProperty%GetJobCreatedByPerson%$JobID$%'
    THEN 'PersonLogic.GetPersonPropertyFromJobID($JobId$, ' + RIGHT(ConfigValue, charindex(',', REVERSE(ConfigValue))-1) + ')'
ELSE
    ConfigValue 
END

To check select both the columns

Select ConfigValue,new_value 
From #TempCustomControls
Sign up to request clarification or add additional context in comments.

1 Comment

Perfect! Thanks for the quick reply.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.