I have this table:
CREATE TABLE [dbo].[INCREMENTAL_TABLE](
[GTIN] [bigint] NOT NULL,
[PRESENTATION] [tinyint] NOT NULL,
[LEVEL] [bigint] NOT NULL,
[INCREMENTAL] [bigint] NOT NULL DEFAULT(0)
CONSTRAINT [PK_INCREMENTAL_TABLE_1] PRIMARY KEY CLUSTERED
(
[GTIN] ASC,
[PRESENTATION] ASC,
[LEVEL] ASC
) ON [PRIMARY]
And now, I'm creating a stored procedure:
CREATE PROCEDURE MyProc
@gint bigint,
@pres tinyint,
@level bigint,
@quantity smallint
AS
DECLARE @current_incremental bigint
DECLARE @counter bigint
-- Get current incremental.
set @current_incremental =
(SELECT INCREMENTAL
FROM INCREMENTAL_TABLE
WHERE GTIN = @gint AND
PRESENTATION = @pres AND
LEVEL = @level)
--
SET @counter = @current_incremental
WHILE ((@counter - @current_incremental) <= @quantity)
BEGIN
SET @counter = @counter + 1
END
GO
Inside this stored procedure I have to create a XML with @quantity nodes. Imagine I have this call:
EXEC MyProc @gint = 1 @pres = 2 @level = 3 @quantity = 100
And, I have this initial value:
@current_incremental = 10
With these data, I have to return a xml with these values:
GTIN | PRESENTATION | LEVEL | INCREMENTAL
-----+--------------+-------+------------
1 | 2 | 3 | 10
-----+--------------+-------+------------
1 | 2 | 3 | 11
-----+--------------+-------+------------
1 | 2 | 3 | 12
[ ... ]
-----+--------------+-------+------------
1 | 2 | 3 | 109
But I'm not going to insert it into the table.
How can I get a XML with these data if I can't do it with a select to that table?