Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 192
  • Last Modified:

create a Field for City and State that is in one field in DB2

So the city and state is in one field in the DB2
what would be the sybtex in SQL 2008 R2 to start on the far right
go back two positions (the State in two positions)
and create that as its own field?
0
jaymz69
Asked:
jaymz69
1 Solution
 
sshah254Commented:
select right(fieldname, 2) from ...
0
 
jaymz69Author Commented:
so that would take the state out and into its own field?

ex.  'SOMEWHERE       ST'

needs to be 'SOMEWHERE'     'ST'
0
 
SharathData EngineerCommented:
try like this.
declare @table table (col varchar(100))
insert @table values ('SOMEWHERE       ST')
select col,
       RTRIM(REVERSE(SUBSTRING(REVERSE(col),3,LEN(col)))) FirstPart,
       REVERSE(LEFT(REVERSE(col),2)) SecondPart
  from @table
/*
col	FirstPart	SecondPart
SOMEWHERE       ST	SOMEWHERE	ST
*/

Open in new window

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now