I'm having the following problem.
My sample data looks as following:
03D
03F
03G
03H
03I
04E
05D
05G
05H
06C
08D
08D (BEST)
08E
08E (BEST)
08F
08F (BEST)
08G
08G (BEST)
08H
08H (BEST)
08I
08I (BEST)
08J
08K
08k08K
08L
08L (BEST)
I need to combine this data into one string that will looks like the following:
03D;03F;03G;03H;03I;04E;05D;05G;05H;06C;08D;08D (BEST);08E;08E (BEST);08F;08F (BEST);08G;08G (BEST);08H;08H (BEST);08I;08I (BEST);08J;08K;08k08K;08L;08L (BEST);
Note that there will always be data added to this table, therefore, I would need this to run accurately, to update a single field using the results of this.
The different values should be split with this operator ;
The script I tried to achieve this is:
declare @loop   int
,       @Tempid int
,       @lookup varchar(max)
    declare @bin table
    (id  int identity primary key, bin varchar(100))
    insert into @bin (bin)
    select distinct
    cBinLocationName
    from    _btblBinLocation
    set @lookup =   ''
                begin
                    select @Loop = min(ID) FROM @bin
                    while @Loop IS NOT NULL
                        begin
                        set @Tempid =   (select id from @bin where id=@Loop)
                            set @lookup =   @lookup + (select bin FROM @bin where ID=@Tempid)+';'
                            select @Loop = min(ID) FROM @bin where ID>@Loop
                        end
                end
    select  @lookup
The problem is, my results is '' the whole time.
Please help?
 
    
