Introduction
In this blogpost I'll try to install and execute some of the views and stored procedures that comes along with the Pubs database.
Views and procedures
The first VIEW I tried was the following script. It will give an error
'CREATE VIEW' must be the first statement in a query batch.
Msg 111, Level 15, State 9, Code line 3
DROP VIEW IF EXISTS titleview;CREATE VIEW titleviewASselect title, au_ord, au_lname, price, ytd_sales, pub_idfrom authors, titles, titleauthorwhere authors.au_id = titleauthor.au_idAND titles.title_id = titleauthor.title_id;
Replacing the ; with a GO succeeds.
DROP VIEW IF EXISTS titleviewGOCREATE VIEW titleviewASselect title, au_ord, au_lname, price, ytd_sales, pub_idfrom authors, titles, titleauthorwhere authors.au_id = titleauthor.au_idAND titles.title_id = titleauthor.title_id;
Later on, I decided to replace all of ; and then all the statements worked very smoothly. This is the script. It succeeds to install, but I noticed that there are "Money" data types in the statements and Money is not supported. I expect that the stored procedure will fail when I try to execute them.
DROP VIEW IF EXISTS titleviewGOCREATE VIEW titleviewASselect title, au_ord, au_lname, price, ytd_sales, pub_idfrom authors, titles, titleauthorwhere authors.au_id = titleauthor.au_idAND titles.title_id = titleauthor.title_idGODROP PROCEDURE IF EXISTS byroyaltyGOCREATE PROCEDURE byroyalty @percentage intASselect au_id from titleauthorwhere titleauthor.royaltyper = @percentageGODROP PROCEDURE IF EXISTS reptq1GOCREATE PROCEDURE reptq1 ASselectcase when grouping(pub_id) = 1 then 'ALL' else pub_id end as pub_id,avg(price) as avg_pricefrom titleswhere price is NOT NULLgroup by pub_id with rolluporder by pub_idGODROP PROCEDURE IF EXISTS reptq2GOCREATE PROCEDURE reptq2 ASselectcase when grouping(type) = 1 then 'ALL' else type end as type,case when grouping(pub_id) = 1 then 'ALL' else pub_id end as pub_id,avg(ytd_sales) as avg_ytd_salesfrom titleswhere pub_id is NOT NULLgroup by pub_id, type with rollupGODROP PROCEDURE IF EXISTS reptq3GOCREATE PROCEDURE reptq3 @lolimit money, @hilimit money,@type char(12)ASselectcase when grouping(pub_id) = 1 then 'ALL' else pub_id end as pub_id,case when grouping(type) = 1 then 'ALL' else type end as type,count(title_id) as cntfrom titleswhere price >@lolimit AND price <@hilimit AND type = @type OR type LIKE '%cook%'group by pub_id, type with rollupGO
Strangly enough when I try to execute the stored procedures, they all work well, ecen the one with the money data type as parameter.
EXEC byroyalty 60
results in :
Final thoughts
Views and Procedures were easy to install and executing went all very well but the money type as a parameter is accepted and no errors happened. The money data is not supported by Microsoft Fabric but may be this is not checked by the engine.
Hennie
Geen opmerkingen:
Een reactie posten