• This trick eliminates loop as well as cursor. 

     

    1) generate a script

    select 'insert into #t exec sp_dba_spaceused ' + name

    from sysobjects where type = 'u'

    order by 1

     

    2) run the script

     

    When writing an automated process, I usually use the loop rather than this "select literal with select set to generate a script" trick, but it is possible to automate running the script that the select statement generates.

    _________________
    "Look, those sheep have been shorn."
    data analyst replies, "On the sides that we can see.."