• ok capn; you just need a function that expands the integers that should bebetween tow numbers as a comma delimited list, is that right?

    here's both an ITVF and a scalar example:

    CREATE FUNCTION fn_ExpandLotRangeitvf( @start int,@end int)

    returns table

    AS

    RETURN

    SELECT STUFF( (SELECT ',' + convert(varchar,MiniTally.n )

    FROM (SELECT TOP 255 ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) AS n

    FROM sys.columns) MiniTally

    WHERE MiniTally.n between @start and @end

    FOR XML PATH('') ) ,1,1,'') As String

    GO

    SELECT * from fn_ExpandLotRangeITVF(2,8)

    GO

    CREATE FUNCTION fn_ExpandLotRange( @start int,@end int)

    RETURNS varchar(1000)

    AS

    BEGIN

    DECLARE @results varchar(1000)

    SELECT @results = STUFF( (SELECT ',' + convert(varchar,MiniTally.n )

    FROM (SELECT TOP 255 ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) AS n

    FROM sys.columns) MiniTally

    WHERE MiniTally.n between @start and @end

    FOR XML PATH('') ) ,1,1,'')

    return @results

    END

    GO

    SELECT dbo.fn_ExpandLotRange(3,10)

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!