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

Help With Null

$
0
0

I have a match-up table and a main table.  In the match-up table I need to display all values accounting for null.  But Null from my matchup table and null from my main table are not matching up.  How can I get these to match-up?  The below shows me both Null from the #ShowAllOfMe table as well as the null values that are in the #MainData table?  I want the 'Null's to match up --- if that makes sense

Create Table #ShowAllOfMe (
  s_state varchar(100),
  region varchar(100)
  )
Create Table #MainData (
  name varchar(100),
  s_state varchar(100),
  address1 varchar(100),
  zip varchar(100) ,
  shippedstatus varchar(100)
  )

Insert Into #ShowAllOfMe(s_state, region)
Values('WA', 'West')
Insert Into #ShowAllOfMe(s_state, region)
Values('LA', 'SE")
Insert Into #ShowAllOfMe(s_state, region)
Values('AL', 'SE')
Insert Into #ShowAllOfMe(s_state, region)
Values('FL', 'South')
Insert Into #ShowAllOfMe(s_state, region)
Values('GA', 'South')
Insert Into #ShowAllOfMe(s_state, region)
Values('NY', 'NE')
Insert Into #ShowAllOfMe(s_state, region)
Values('', 'NE')

Insert Into #MainData(name, s_state, address1, zip, shippedstatus)
Values('Roy Orbinson', '', '2222 Hold', '1234', 'In Transit')
Insert Into #MainData(name, s_state, address1, zip, shippedstatus)
Values('Roy', 'FL', '2112 Hold', '1234', 'In Transit')
Insert Into #MainData(name, s_state, address1, zip, shippedstatus)
Values('Roy Orbinson', 'GA', '2211 Hold', '1234', 'Pending')

Select a.s_state, a.region, ISNULL(Count(b.shippedStatus),0)
FROM #ShowAllOfMe a
left Join #MainData b
ON a.s_state = b.s_state
and b.shippedstatus IS NOT NULL
Group By a.s_state, a.region


Viewing all articles
Browse latest Browse all 23857

Trending Articles



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