Trying to insert results from sp_spaceused (tablename) into different table.

  • Hi SQL gurus I am trying to track space of a table of Adventureworks and like to insert into a table into AAA database and run that thru SQL agent with date stamped.

    Can someone help?

    use AAA

    go

    create table A(

    Rundate DATETIME NOT NULL DEFAULT(GETDATE())

    ,objname varchar(100)

    ,rows varchar (10)

    ,reserved varchar(10)

    ,data varchar(10)

    ,index_size varchar(10),

    unused varchar(10))

    Go

    insert into aaa (

    objname varchar(100)

    ,rows varchar (10)

    ,reserved varchar(10)

    ,data varchar(10)

    ,index_size varchar(10),

    unused varchar(10))

    (

    exec '(sp_spaceused 'AdventureWorks.person.address')'

  • Remove the parenthesis and the related single quotes from the EXEC.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • did this: exec sp_spaceused 'AdventureWorks.person.address' still not working 🙁

  • If you provide the database name, it has to be that of the current database.

  • USE AAA

    GO

    create table A(

    Rundate DATETIME NOT NULL DEFAULT(GETDATE())

    ,objname varchar(100)

    ,rows varchar (10)

    ,reserved varchar(10)

    ,data varchar(10)

    ,index_size varchar(10),

    unused varchar(10))

    Go

    insert into A (

    objname

    ,rows

    ,reserved

    ,data

    ,index_size

    ,unused)

    exec AdventureWorks..sp_spaceused 'AdventureWorks.person.address'

  • Dan121 (2/25/2015)


    did this: exec sp_spaceused 'AdventureWorks.person.address' still not working 🙁

    Heh... what does that mean? "Still not working". Are you getting an error? What are the symptoms?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Worked!!!!Thanks you millions Kutang and Jeff you guys are awesome:-)

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply