Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
darenkov
Yak Posting Veteran
90 Posts |
Posted - 2007-11-30 : 21:57:38
|
| i am trying to move the numbers from column one into the next column (postcode). this is in the same table called companydetailshere is my sample data:SUB/STATE/PC POSTCODE------------------|--------------Windy Hills 6045 NULLChestermere 6189 NULLMt Lawley 7468 NULLhere is my lame attempt to do this:update companydetails set [Postcode] = (select right([sub/state/pc],4) from companydetails) |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-12-01 : 01:23:53
|
| If you are sure that last 4 digits are numbers thenupdate companydetails set [Postcode]=right([sub/state/pc],4)MadhivananFailing to plan is Planning to fail |
 |
|
|
ranganath
Posting Yak Master
209 Posts |
Posted - 2007-12-01 : 01:33:35
|
| hi,try thisDECLARE @T TABLE ([SUB/STATE/PC] varchar(1000), postcode int)INSERT INTO @TSELECT 'Windy Hills 6045',NULL UNION ALLSELECT 'Chestermere 6189', NULL UNION ALLSELECT 'Mt Lawley 7468', NULL--SELECT * FROM @TUPDATE ASET Postcode = stuff(RIGHT ([SUB/STATE/PC],charindex(' ',reverse([SUB/STATE/PC]))),1,1,'')FROM @T ASELECT * FROM @T |
 |
|
|
darenkov
Yak Posting Veteran
90 Posts |
Posted - 2007-12-01 : 04:43:22
|
| thanks guys |
 |
|
|
|
|
|