Created
March 10, 2015 14:45
-
-
Save duyet/a0b39057decb8234996f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE PROCEDURE [dbo].[TinhSoSachCuaLoaiSach] | |
@MaLoaiSach char(4), | |
@SoSach int OUTPUT | |
AS | |
BEGIN | |
SET NOCOUNT ON; | |
DECLARE | |
@cur_tuade CURSOR, | |
@tuade char(9) | |
SET @SoSach = 0 | |
SET @cur_tuade = CURSOR FORWARD_ONLY | |
FOR SELECT MaTuaDe FROM dbo.TUADESACH WHERE MaLoaiSach = @MaLoaiSach | |
OPEN @cur_tuade | |
FETCH NEXT FROM @cur_tuade INTO @tuade | |
WHILE @@FETCH_STATUS = 0 | |
BEGIN | |
SET @SoSach = @SoSach + (SELECT COUNT(*) FROM dbo.CUONSACH WHERE MaTuaDe = @tuade) | |
FETCH NEXT FROM @cur_tuade INTO @tuade | |
END | |
CLOSE @cur_tuade | |
DEALLOCATE @cur_tuade | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment