+ 2
Best way to create long stored procedure
basiscs of sql stored procedure
3 ответов
+ 1
Hey bro can you help me with another procedure?
0
CREATE PROC spShowYears(
@StartYear int,
@EndYear int
)
AS
-- create a table of years
DECLARE @tblYears TABLE (
YearId int IDENTITY(1,1) PRIMARY KEY,
YearNumber int,
NumberDirectors int,
NumberActors int
)
-- populate it with n years
DECLARE @year int
SET @year = @StartYear
WHILE @year <=>
BEGIN
-- insert into table this year
INSERT INTO @tblYears (
YearNumber,
NumberDirectors,
NumberActors
) VALUES (
@year,
0,
0
)
SET @year = @year + 1
END
-- set how many directors born in each year
UPDATE
@tblYears
SET
NumberDirectors = (
SELECT COUNT(*) FROM tblDirector
WHERE Year(DirectorDob) = YearNumber
)
-- set how many actors born in each year
UPDATE
@tblYears
SET
NumberActors = (
SELECT COUNT(*) FROM tblActor
WHERE Year(ActorDob) = YearNumber
)
-- return results
SELECT
*
FROM
@tblYears
0
what to do.. to create amd understand procedures.....