I am crating a view to display records with contract dates in them.
The data for this view comes from two tables, one which stores the client details and another which stores the date info.
The dates themeselves are stored in the DateCol column and the ID for the DateCol column comes from TypeID eg 118 equals a Contract Start Date and 119 equals an End date.
This returns about 250 results.
The view I have built runs a lookup against the client id and shows the date from the date_type(ie 118 and 119 shows 01/01/2012 and 01/03/2012). If I add a third column that shows me 120, the total number of results is reduced to 6.
I need to see all the results but im not sure how to build a view that shows all of these. I cant modify the original database as it is a backed for Maximizer.
We are using SQL 2005 and I have built this using the Management STudio but my knowledge is a bit limited.
This is the code for my view:
SELECT *
FROM dbo.AMGR_Client_Tbl
INNER JOIN dbo.FOOTPRINTS_Companies_118
ON dbo.AMGR_Client_Tbl.Client_Id =
dbo.FOOTPRINTS_Companies_118.Client_Id
INNER JOIN dbo.FOOTPRINTS_Companies_119
ON dbo.AMGR_Client_Tbl.Client_Id =
dbo.FOOTPRINTS_Companies_119.Client_Id
INNER JOIN dbo.FOOTPRINTS_Companies_120
ON dbo.AMGR_Client_Tbl.Client_Id =
dbo.FOOTPRINTS_Companies_120.Client_Id
INNER JOIN dbo.FOOTPRINTS_Companies_121
ON dbo.AMGR_Client_Tbl.Client_Id =
dbo.FOOTPRINTS_Companies_121.Client_Id
WHERE ( dbo.AMGR_Client_Tbl.Record_Type = '1' ) AND ( dbo.AMGR_Client_Tbl.Name_Type = 'C' )
OR ( dbo.AMGR_Client_Tbl.Record_Type = '1' ) AND ( dbo.AMGR_Client_Tbl.Name_Type = 'C' )
Ok, First of all you should list the actual column names that you need on your view and not use
*. I believe that you just need to change theINNER JOINs forLEFT JOINs. So it would be like this:Also, you should note that on your
WHEREthere seems to be a duplicated condition.