Altering View in MS SQL Server by Adding Col based on Join

by Joel   Last Updated January 11, 2018 04:06 AM

I have created a view that queries a table called Sheet1$. It has a carID field, and a carName field.

So I created my view by doing the following:

CREATE VIEW corvettes AS SELECT * FROM Sheet1$ WHERE carName = 'corvette'

I have another table called Sheet2. It has a carID field, and a carYear field. I want to alter my original view by adding a COL to it called YEAR and then populate YEAR with the values of Sheet2$.carYear via join of the two carID fields.

I can get the YEAR field appended with the correct data, but if there is no match of the ID's, then the whole row goes away. I'd rather have the YEAR say NULL instead of going away if the ID's don't match.

This is what I have. Where am I going wrong?

ALTER VIEW corvettes AS SELECT a.carID, a.carName, b.carYear FROM Sheet1$ a, Sheet2$ b WHERE a.carID = b.carID AND carName = 'corvette'

Tags : sql-server sql

Related Questions

creating index on big table(s)

Updated September 03, 2018 18:06 PM

Linked Server Error on SQL Agent Job

Updated March 16, 2016 08:02 AM