CREATE FUNCTION [dbo].[rowsFromValue](@qty int)
RETURNS @retArray TABLE (idx smallint Primary Key)
AS
BEGIN
DECLARE @idx smallint
IF @qty = null
BEGIN
SET @qty = 0
END
SET @idx = 0
WHILE @qty > 0
BEGIN
SET @idx = @idx + 1
INSERT @retArray (idx)
VALUES (@idx)
SET @qty = @qty - 1
END
RETURN
END
GO
CREATE TABLE [PRODUCT](
[UPC] [varchar](14) NULL,
[ONHAND_QTY] [int] NULL)
SELECT
UPC
,PM_TITLE
,IDX
FROM PRODUCT AS P
CROSS APPLY [Cognos].[dbo].[rowsFromValue](ONHAND_QTY) AS R
|