Last active
December 11, 2017 21:09
-
-
Save janosorcsik/08b6058a70b005ba9e3ddc21dba69adf to your computer and use it in GitHub Desktop.
Annyi sor, amennyi az intervantionumber
This file contains 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 FUNCTION [dbo].[MDI_CTE] (@ID BIGINT) | |
RETURNS @MID_CTE TABLE | |
( | |
ID BIGINT, | |
ToothCode NVARCHAR(64), | |
InterventionCode NVARCHAR(16), | |
BNOCode NVARCHAR(16), | |
ToBeReported BIT, | |
DentistryPatientDatacardID BIGINT, | |
InterventionNumber INT | |
) | |
AS | |
BEGIN | |
INSERT INTO @MID_CTE | |
SELECT | |
ID, | |
ToothCode, | |
InterventionCode, | |
BNOCode, | |
ToBeReported, | |
DentistryPatientDatacardID, | |
InterventionNumber | |
FROM ModToothInterventions | |
WHERE ID = @ID | |
DECLARE @CurrentRow INT = 1 | |
DECLARE @LastRow INT | |
SELECT @LastRow = InterventionNumber | |
FROM @MID_CTE | |
WHILE @CurrentRow < @LastRow | |
BEGIN | |
INSERT INTO @MID_CTE | |
SELECT | |
ID, | |
ToothCode, | |
InterventionCode, | |
BNOCode, | |
ToBeReported, | |
DentistryPatientDatacardID, | |
InterventionNumber | |
FROM ModToothInterventions | |
WHERE ID = @ID | |
SET @CurrentRow = @CurrentRow + 1 | |
END | |
RETURN | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment