Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
CREATE or alter VIEW Branch_info (Branch_Name,Branch_id,No_of_customers )
AS 
SELECT Branch_Name,Branch_id, COUNT(*)
FROM Branch , customer	,	Buysfrom

where Branch.Branch_id=	Buysfrom.Bid
customer.Customer_id2=Buysfrom.Cid
GROUP BY Branch_Name, Branch_id;


What I have tried:

here customer is highlited as an error I do not why it is wrong
Quote:
Msg 156, Level 15, State 1, Line 113
Incorrect syntax near the keyword 'or'.
Msg 111, Level 15, State 1, Line 113
'ALTER VIEW' must be the first statement in a query batch.
Msg 102, Level 15, State 1, Line 119
Incorrect syntax near 'customer'.
Posted
Updated 14-Dec-22 3:00am
v2
Comments
Graeme_Grant 14-Dec-22 8:51am    
Please watch your tagging of your questions. This has nothing to do with CSS/CSS3.

What error? Please post the error message that you are seeing.
Noran Azab 14-Dec-22 8:53am    
Msg 156, Level 15, State 1, Line 113
Incorrect syntax near the keyword 'or'.
Msg 111, Level 15, State 1, Line 113
'ALTER VIEW' must be the first statement in a query batch.
Msg 102, Level 15, State 1, Line 119
Incorrect syntax near 'customer'.

CREATE OR ALTER was introduced in SQL Server 2016 SP1. If it's not working, then you have an earlier version of SQL Server which doesn't support that syntax.

KB3190548 - Update introduces CREATE OR ALTER Transact-SQL statement in SQL Server 2016 - Microsoft Support[^]

You either need to update to a version of SQL Server that supports this syntax, or use an alternative syntax instead.

You also still need to use proper JOINs, and get rid of the ancient pre-ANSI-92 syntax you're using everywhere:
SQL
SELECT Branch_Name, Branch_id, COUNT(*)
FROM Branch
INNER JOIN customer ON customer.Customer_id2 = Buysfrom.Cid
INNER JOIN Buysfrom ON Buysfrom.Bid = Branch.Branch_id
GROUP BY Branch_Name, Branch_id;
 
Share this answer
 
You seem to be having a lot of problems with your SQL code. Maybe spending some time at SQL CREATE VIEW, REPLACE VIEW, DROP VIEW Statements[^] would be a good idea.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900