• If i only could put here the code, ehhh

    alter procedure [dbo].[test]@multiple_weeks varchar(4000)

    as

    declare

    @val date

    create table #ps(id varchar(30),week varchar(8)[...])

    declare c1 cursor for

    select CONVERT(varchar,Item,112) FROM [dbo].[DelimitedSplit8K](@multiple_weeks ,',') Myfn

    open c1

    fetch next from c1 into @val

    While @@fetch_status <> -1

    begin

    insert into #ps id,CONVERT(varchar,@val,112), [...] -- complicated select with a lot of calculations

    fetch next from c1 into @val

    end

    close c1

    deallocate c1

    select [week, id, etc] -- select from temp table with calculations

    from (select week, id, etc from #ps ) d

    where date in @multiple_weeks -- they have here where however data previously are selected only for 2 dates

    The schema is like this. When i execute it for one date, its ok, for second, its ok. But when i execute it for 2 dates, i see in PRINT commands parameters in cursor are ok (Date is changing) but i have no data.

    I have deleted last where and i got data but data for first date duplicated with second date as below

    20150101 10 12

    20150106 10 12

    20150101 15 20

    20150106 15 20

    Maybe im ending the cursor in wrong place? But i dont think so. If i end it after select, i would get 2 separate sets of data