Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Trying to join two views that have different column types

$
0
0

I want to join view1 and view2 on region and city int columns. Need to break apart View1 varchar field into two Int fields and replace any non-numeric values with zeros.

View1 has a single Region_City field that is VARCHAR. the last record is erroneous. the individual values for Region and City should always be Int. 
0001-8374
0222-0034
3333-0001
XXA-EEE

View2 has Region and City as two seperate Int columns (i will seperate with comma just for display)
Region,City
1,8374
222,34
3333,1

I want to create two new individual columns in view1 that will have Region and City each as a Int. And for any Region_city that is invalid numeric just use zeros in Region and City.

I currently have this (in house ParseDelimited sproc), but am having trouble with the invalid numeric values (XXAA-EEE)

REPLACE(LTRIM(REPLACE(dbo.ParseDelimited (Region_City, '-', 1), '0', ' ')), ' ', '0') as Region,
REPLACE(LTRIM(REPLACE(dbo.ParseDelimited (Region_City, '-', 2), '0', ' ')), ' ', '0') as City,


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>