I have data stored in a table that requires specific values to be removed so it can be shared more widely.
The data that needs to be removed will have a key as below:
Data Table
| Statement | Answer |
| ------------ | ------------ |
| First Name | Mike |
| Last Name | Smith |
| Position | Fitter |
| Country | France |
| Years Worked | 25 |
Look up
Key | Return |
---|---|
First Name | Redacted |
Last Name | Removed |
Country | Not Available |
Output:
Statement | Answer |
---|---|
First Name | Redacted |
Last Name | Removed |
Position | Fitter |
Country | Not Available |
Years Worked | 25 |
I tried using a join and I tried using SET to match the columns when Statement = Key. Both of these I managed to replace the values in the Answer column with values in Return but it also replaced the values that didn't have a match in the look up column with NULL
Code I have tried:
SELECT *
FROM [Data Table] DATA
LEFT JOIN [Lookup up] DSL
ON DATA.[Statement] = DSL.[Key]
and
UPDATE [Data Table Sanitised]
SET [Answer] = (
SELECT [Return]
FROM [Look up]
WHERE [Key] = [Statement]
)
Both returned:
Statement | Answer |
---|---|
First Name | Redacted |
Last Name | Removed |
Position | NULL |
Country | Not Available |
Years Worked | NULL |
1条答案
按热度按时间oxf4rvwz1#
Using your example data:
This gives the expected output:
Result: