Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
I need to make sure the states are insynch between the two tables. First table lists the state, and the other table lists the city and state with a comma as the delimiter. Any thoughts?
sodeep
Master Smack Fu Yak Hacker
7174 Posts
Posted - 2009-02-23 : 14:52:54
And what did you try?
s.wiley7
Starting Member
4 Posts
Posted - 2009-02-23 : 15:02:49
SELECT A.STATE_CD, C.CITY_STATE_CDFROM temp1 a, temp2 cWHERE A.STATE_CD IS NOT NULL AND C.CITY_STATE_CD IS NOT NULLand C. C.CITY_STATE_CD like '%,%'and STATE_CD = C. C.CITY_STATE_CD <---not sure how to set up to parse
sodeep
Master Smack Fu Yak Hacker
7174 Posts
Posted - 2009-02-23 : 15:07:20
Maybe:
Select * from Tbl1 tLeft outer join Tb2 mOn t.State_CD = Right(C.City_state_cd,2)Where Right(C.City_state_cd,2) Is NULL
s.wiley7
Starting Member
4 Posts
Posted - 2009-02-23 : 16:10:23
That didn't work.
sodeep
Master Smack Fu Yak Hacker
7174 Posts
Posted - 2009-02-23 : 16:28:35
It should work:Anyway try this:
Select * from Tbl1 tLeft outer join Tb2 mOn t.State_CD = Substring(C.City_state_cd,Charindex(',',C.City_state_cd)+1,2)Where Substring(C.City_state_cd,Charindex(',',C.City_state_cd)+1,2) Is NULL