Und weiter geht mit meinen Fragen. Dies mal zu einer FOR-Schleife. Unzwar möchte ich 2 FOR-Schleifen in eine Funktion einbauen, mit der eine temporäre Tabelle erstellt werden soll.
Zitat:
USE [Zeit]
GO
/****** Object: UserDefinedFunction [dbo].[Start_AWJ] Script Date: 11/13/2009 16:52:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE FUNCTION [dbo].[Start_AWJ_2]
(
-- Add the parameters for the function here
@startmonat smallint,
@endmonat smallint
)
RETURNS
@tmpAWJ_Monate TABLE
(
-- Add the column definitions for the TABLE variable here
AWJ_Monate smallint
)
AS
BEGIN
-- Fill the table variable with the rows for your result set
declare @schreibmonat smallint
set @startmonat = ( SELECT AWJ_Start FROM AWJ_Start )
set @endmonat = @startmonat -1
declare i smallint
FOR i IN @startmonat .. 12 LOOP
INSERT INTO
@tmpAWJ_Monate
SELECT
@schreibmonat as AWJ_Monate
set @schreibmonat=i
END LOOP;
RETURN
END |
So sieht es bisher aus.
Was muss ich für die FOR-Schleife deklarieren? Ich möchte das die erste FOR-Schleife die Werte von der Variable "@startmonat", die ich aus einer Tabelle abgreife, bin zum Wert 12 die Spalte "AWJ_Monate" der temporären Tabelle schreibt. Und das die zweite FOR-Schleife die Werte von 1 bis zur Variable "@endmonat" ( = @startmonat -1) auch in die Spalte "AWJ_Monate" schreibt.
So. Ma sehn, war das alles? Wenn mir jemand helfen möchte, und noch mehr Infos braucht bitte melden.
Bis dann