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 |
|
NeilC
Yak Posting Veteran
55 Posts |
Posted - 2007-08-08 : 12:26:17
|
| I have a column with the following data:OwnerASHDOWN, AR 71822I need to grab the zip code and insert it into a zip column - how can I do this with sub string? Or is there an easier way? |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2007-08-08 : 12:30:43
|
| [code]DECLARE @zip varchar(50)select @zip = 'ASHDOWN, AR 71822'select RIGHT(@zip, CHARINDEX(' ', REVERSE(@zip)))[/code]_______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenp |
 |
|
|
NeilC
Yak Posting Veteran
55 Posts |
Posted - 2007-08-08 : 12:50:38
|
| Thanks Spirit1, I have over 10,000 records that I need to work on and in this example @zip is hardcoded. I need to grab the zip out of the owner column in every record and insert it into a new column called zip - how can that be done dynamically? |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2007-08-08 : 13:02:53
|
| select RIGHT(YourZipColumn, CHARINDEX(' ', REVERSE(YourZipColumn)))from yourTablethis will only work if your zips are at the end of each row,a space is before them asnd they have no space in them._______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenp |
 |
|
|
|
|
|