My tables
CREATE TABLE Reference (
ReferenceId int NOT NULL IDENTITY(1,1) PRIMARY KEY,
RefType varchar(20) NOT NULL,
RefDescription varchar(30),
Deleted bit NOT NULL default '0',
DeletedON date NULL)
CREATE TABLE Customers (
CustomerId int NOT NULL IDENTITY(1,1) PRIMARY KEY,
CustomerTypeId int NOT NULL,
FirstName varchar(20) NOT NULL,
LastName varchar(20) NOT NULL,
DateOfBirth date NOT NULL,
AddressLine1 varchar(60) NOT NULL,
City varchar(20) NOT NULL,
Country varchar(20) NOT NULL,
PhoneNumber int NOT NULL,
Email varchar(20) NOT NULL,
CONSTRAINT FK_CustomerTypeId FOREIGN KEY (CustomerTypeId) REFERENCES Reference (ReferenceId)
CREATE TABLE Association (
AssoId int NOT NULL IDENTITY(1,1) PRIMARY KEY,
AssoTypeId int NOT NULL,
Cust1Id int NOT NULL,
Cust2Id int NOT NULL,
CONSTRAINT FK_Customer1Id FOREIGN KEY (Cust1Id) REFERENCES Customers (CustomerId),
CONSTRAINT FK_Customer2Id FOREIGN KEY (Cust2Id) REFERENCES Customers (CustomerId),
CONSTRAINT BothClientsUnique UNIQUE (Cust1Id,
Cust2Id),
CONSTRAINT FK_AssoTypeId FOREIGN KEY (AssoTypeId) REFERENCES Reference (ReferenceId))
CREATE TABLE Accounts (
AccountsId int NOT NULL IDENTITY(1,1) PRIMARY KEY,
AccountsTypeId int NOT NULL,
CustomerId int NOT NULL,
AccUsername varchar(15) NOT NULL,
AccPass varchar(12) NOT NULL,
CONSTRAINT FK_CustomerId FOREIGN KEY (CustomerId) REFERENCES Customers (CustomerId),
CONSTRAINT FK_AccountsTypeId FOREIGN KEY (AccountsTypeId) REFERENCES Reference (ReferenceId))
SecuritiesId int NOT NULL IDENTITY(1,1) PRIMARY KEY,
SecTypeId int NOT NULL,
SecValue int NOT NULL,
SecValueDate date NOT NULL,
AccountsId int NOT NULL,
CONSTRAINT FK_AccountsId FOREIGN KEY (AccountsId) REFERENCES Accounts (AccountsId),
CONSTRAINT FK_SecTypeId FOREIGN KEY (SecTypeId) REFERENCES Reference (ReferenceId)
)
My View (single view on all their clients and the touch points between them)
SQL View which will return the association details between all clients
ALter view [dbo].[fullcustdata] asSelect
CS.[FirstName],
CS.[LastName] ,
AC.[AccUsername],
RF.[RefType] as ''Account_Type'',
RF1.[RefType] as ''Associotion_Type'',
RF2.[RefType] as ''Security_Type'',
S.[SecValue],
S.[SecValueDate]
From
[dbo].[Securities] S
LEFT OUTER JOIN
[dbo].[Accounts] AC
on
AC.[AccountId] = S.[AccountId]
LEFT OUTER JOIN
[dbo].[Customers] CS
on
CS.[CustomerId] = A.[CustomerId]
LEFT OUTER JOIN
[dbo].[Association] AT
on
CS.[CustomerId] = AT.[Cust1Id]
LEFT OUTER JOIN
[dbo].[Associaton] BT
on
CS.[CustomerId] = BT.[Cust2Id]
LEFT OUTER JOIN
[dbo].[Reference] RF
on
RF.[ReferenceId] = AC.[AccTypeId]
LEFT OUTER JOIN
[dbo].[Reference] RF1
on
RF1.[ReferenceId] = AT.[AssoTypeId]
LEFT OUTER JOIN
[dbo].[Reference] RF2
on
RF2.[ReferenceId] = S.[SecTypeId]
GO
My Error
Msg 1038, Level 15, State 4, Procedure fullcustdata, Line 8An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as "" or [] are not allowed. Change the alias to a valid name.