Skip to content

Instantly share code, notes, and snippets.

@janosorcsik
Last active December 11, 2017 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janosorcsik/08b6058a70b005ba9e3ddc21dba69adf to your computer and use it in GitHub Desktop.
Save janosorcsik/08b6058a70b005ba9e3ddc21dba69adf to your computer and use it in GitHub Desktop.
Annyi sor, amennyi az intervantionumber
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