Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear

I have an query in my table & column name is registration number which data type is varchar ..

values contain in this column like--

regi01001
regi01002


i want to update above values in the table..

regi02001
regi02002


pls help me to solve above problem....
Posted

1 solution

HI Mukesh,

Check the following Scripts....

SQL
-- Table Creation
IF OBJECT_ID('TempDB..#RegDtls') IS NOT NULL DROP TABLE #RegDtls
CREATE TABLE #RegDtls(RegNo VARCHAR(50))
-- Sample Data
INSERT INTO #RegDtls(RegNo) VALUES('regi01001'),('regi01002')
-- Actual Data
SELECT RegNo FROM #RegDtls
-- Update Statement
UPDATE #RegDtls SET RegNo='regi'+RIGHT('00000'+CAST(SUBSTRING(RegNo,5,10)+1000 AS VARCHAR(10)),5)
-- Required Output
SELECT RegNo FROM #RegDtls
 
Share this answer
 
Comments
RedDk 17-Feb-13 13:38pm    
... oh, so that's how one uses UPDATE ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900