+ 2

Best way to create long stored procedure

basiscs of sql stored procedure

13th May 2018, 7:02 AM
Mohan Negi
Mohan Negi - avatar
3 Réponses
+ 1
Hey bro can you help me with another procedure?
17th May 2018, 10:40 PM
Стас Белич
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
16th May 2018, 10:12 AM
Rajeeb
0
what to do.. to create amd understand procedures.....
18th May 2018, 2:46 PM
Mohan Negi
Mohan Negi - avatar