Reputation: 109
I'm trying to create a simple little view but I'm keep getting errors all over the query. [Accepted by Month]
has the error No column was specified for column 1 of 'Accepted by Month'
. I have looked up pretty much everything online and I know that I need to give the columns I select an alias but whenever I do that it just gives me an error under the AS
I use for the column aliases saying incorrect syntax near
. Plus I'm getting errors with the comma in the SELECT
statement and an error for FROM
both saying incorrect syntax.
Someone show me how I should write this query because I haven't made any progress in over an hour on a simple CREATE VIEW
.
USE Database_Name
GO
CREATE VIEW [Accepted by Month] AS
SELECT Case.Accepted, Case.CaseID
FROM Case;
Upvotes: 0
Views: 258
Reputation: 12940
You can use the following to solve your problem:
USE Database_Name
GO
CREATE VIEW [Accepted by Month] AS
SELECT [Case].Accepted, [Case].CaseID
FROM [Case];
Upvotes: 1
Reputation: 14928
The brackets are required if you use keywords or special chars in the column names or identifiers or names with white space.
USE Database_Name
GO
CREATE VIEW [Accepted by Month] (Accepted, CaseID) AS
SELECT Accepted, CaseID
FROM [Case];
Upvotes: 0