Reputation: 161
I have this SQL Query:
SELECT a.NAME
,(CASE
WHEN a.TIME = b.schedule
THEN 0
ELSE 1
END ) AS number
INTO C
FROM a
INNER JOIN b
ON a.NAME = b.NAME;
It creates the 3rd table as needed but the table is empty and I assure you the time column from A does not match all of schedule column from B.
I noticed the JOIN is greyed out which I have reason to believe is what is causing the issue, but is there anything I missed for this query to function as needed? Thanks in advance, any help is appreciated.
Upvotes: 0
Views: 5644
Reputation: 674
You mention in your comment that the query works with a left join
. That means that your a.Name = b.Name
condition is failing when you try to do an inner join
.
In this case, you'll need to figure out why they don't match each other appropriately, if there is a leading space for instance.
Based on your comment, your columns don't match, so you'll need to do some creative querying to get what you want (assuming you can't fix the data). It's ugly and not a great way to do it but you could try matching on just the beginning of the field, up to the semi-colon:
SELECT a.NAME
,(CASE
WHEN a.TIME = b.schedule
THEN 0
ELSE 1
END ) AS number
INTO C
FROM a
INNER JOIN b
on substring(a.Name,1,CHARINDEX(';',a.Name)) = substring(b.Name,1,CHARINDEX(';',b.Name))
Upvotes: 1