Home Forums SQL Server 7,2000 T-SQL variable tablename in cursor select stmt RE: variable tablename in cursor select stmt

  • What would be your max number of tables per @countyt?

    I'm thinking something in the line of

    (David's modified)

     
    
    declare @sql nvarchar(4000)
    set @sql = 'DECLARE cursor2
    CURSOR GLOBALDYNAMIC FOR
    SELECT Convert(Int, 0) as SumOf_file_size_bytes , Convert(Char(x), NULL) as Lseries WHERE 1=2 -- Dummy to establish structure' + Char(13) + Char(10)

    Select @sql = @sql +
    'UNION ALL SELECT sum(file_size_bytes) , Lseries
    from Volume_Control.dbo.tblFilenames_' + Qualifier + Lseries + '
    group by Lseries FOR READ ONLY' + Char(13) + Char(10)
    From LandRecords..tblLandRec_Index_Series where County=@countyt
    exec(@sql)



    Once you understand the BITs, all the pieces come together