Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Add EA to the start of a field in a column Expand / Collapse
Author
Message
Posted Tuesday, October 15, 2013 9:29 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, October 15, 2013 9:23 AM
Points: 14, Visits: 18
I am new to sql and would like your help. I have a table that lists an payroll reference number for all the workers in the business. for example

Emma Davies 01234568
Jo Bloggs 45685214

I need to update the Payroll_reference filed so they all start with EA. So after update is will be

Emma Davies EA01234568
Jo Bloggs EA45685214

I have used this but it did not work. Any ideas please?

Update pdcontacts
set Payroll_ref = 'EA' + 'Payroll_ref'

Post #1504822
Posted Tuesday, October 15, 2013 9:32 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 1:28 PM
Points: 2,386, Visits: 7,611
emdavies82 (10/15/2013)
I am new to sql and would like your help. I have a table that lists an payroll reference number for all the workers in the business. for example

Emma Davies 01234568
Jo Bloggs 45685214

I need to update the Payroll_reference filed so they all start with EA. So after update is will be

Emma Davies EA01234568
Jo Bloggs EA45685214

I have used this but it did not work. Any ideas please?

Update pdcontacts
set Payroll_ref = 'EA' + 'Payroll_ref'



You've quoted 'Payroll_ref', so that makes it a literal string. Your essentially said: -
Update all Payroll_ref columns to "EAPayroll_ref".

Try: -
BEGIN TRANSACTION;

UPDATE pdcontacts
SET Payroll_ref = 'EA' + Payroll_ref;

--Check results
SELECT *
FROM pdcontacts;

--Rollback changes
ROLLBACK;
--COMMIT;
--Comment out ROLLBACK and uncomment COMMIT when you're happy that this does what you expect.




Not a DBA, just trying to learn

For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/

For better, quicker answers on SQL Server performance related questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/



If you litter your database queries with nolock query hints, are you aware of the side effects?
Try reading a few of these links...

(*) Missing rows with nolock
(*) Allocation order scans with nolock
(*) Consistency issues with nolock
(*) Transient Corruption Errors in SQL Server error log caused by nolock
(*) Dirty reads, read errors, reading rows twice and missing rows with nolock


LinkedIn | Blog coming soon (for sufficiently large values of "soon" )!
Post #1504825
Posted Tuesday, October 15, 2013 9:39 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, October 15, 2013 9:23 AM
Points: 14, Visits: 18
Thank you so much for the fast response
Post #1504831
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse