I am trying to change the name of a stored value when I execute my SQL script:
SELECT
PERSONNUM,
PAYCODENAME,
CAST(WFCTIMEINSECONDS AS FLOAT)/3600 AS Total_Hours
FROM
VP_ALLTOTALS
WHERE
Applydate >= '09/25/2011' AND
Applydate <= '10/01/2011' AND
PAYCODENAME IN ('Vacation'
,'Sick Leave - Paid'
,'Personal Business - Paid'
,'Comp Time - Paid'
)
I want the Vacation to be VAC, Sick Leave - Paid to be SIC, Personal Business - Paid to be PER and
First, specify the table name that you want to change data in the UPDATE clause. Second, assign a new value for the column that you want to update. In case you want to update data in multiple columns, each column = value pair is separated by a comma (,). Third, specify which rows you want to update in the WHERE clause.
The Replace statement is used to replace all occurrences of a specified string value with another string value. The Replace statement inserts or replaces values in a table. Use the Replace statement to insert new rows in a table and/or replace existing rows in a table.
SQL Server permits you to change the column whenever required. You need to rename column in SQL where the column name is meaningless or doesn't meet its purpose.
SQL Server REPLACE() FunctionThe REPLACE() function replaces all occurrences of a substring within a string, with a new substring. Note: The search is case-insensitive.
The easiest way is a list of CASE
options for substitutions.
SELECT PERSONNUM
PAYCODENAME CASE WHEN 'Vacation' THEN 'VAC'
WHEN 'Sick Leave - Paid' THEN 'SIC'
WHEN 'Personal Business - Paid' THEN 'PER'
ELSE PAYCODENAME END AS PAYCODENAME
....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With