Search code examples
asp-classicloopsresultset

Loop through resultset and add create comma separated string in ASP Classic


Here's my ASP Classic:

set irs  = recordset(sql,PageDB)            
    if not irs.eof then

        dim new_list
        new_list = ""

        do while not irs.eof

            'Add irs("name") to new_list and separate by comma      

        irs.movenext

        loop

    end if

kill(irs)

How would I add irs(name) to new_list and separate by a comma?


Solution

  • set irs  = recordset(sql,PageDB)            
        if not irs.eof then
    
            dim new_list
            new_list = ""
    
            do while not irs.eof
    
                new_list = new_list & irs("name") & ","     
    
            irs.movenext
    
            loop
    
            new_list = left(new_list, len(new_list)-1)
    
        end if
    
    kill(irs)