SQL - SELECT statement

  • Dear All.

    I am receiving this error message "Only one expression can be specified in the select list when the subquery is not introduced with EXISTS" to  the statement below :

    declare @tamanho as varchar(10)

    SET @tamanho= (select substring(name,1,30) as Banco,

                   CAST( ( FILEPROPERTY( name, 'SpaceUsed' ) * 8 ) / 1024 AS numeric( 10, 2) )

                   FROM sysfiles)

    go

    Please, somebody can help...

    Thanks,

    Flavio Bendl

     

     

  • Well,

    If you execute this code alone, how many records are returned?

    select substring(name,1,30) as Banco,

                   CAST( ( FILEPROPERTY( name, 'SpaceUsed' ) *  ) / 1024 AS numeric( 10, 2) )

    FROM sysfiles

    More than 1.

    So which one do you want to use to set the variable to?

     

  • IANAD, (I am not a developer) but see if this helps:

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/acdata/ac_8_qd_11_9nw3.asp

     

     

    My hovercraft is full of eels.

  • Try:

    declare @tamanho varchar(10)

    select @tamanho=substring(name,1,10),

           --CAST((FILEPROPERTY(name, 'SpaceUsed')* 8)/1024 AS numeric(10,2))

    FROM sysfiles

    SELECT @tamanho

    or:

    declare @tamanho varchar(10)

    select @tamanho=

           --substring(name,1,30) as Banco,

           CONVERT(varchar(10),CAST((FILEPROPERTY(name, 'SpaceUsed')* 8)/1024 AS numeric(10,2)))

    FROM sysfiles

    SELECT @tamanho

    or:

    declare @tamanho numeric(10,2), @banco varchar(30)

    select @banco=substring(name,1,30),

           @tamanho=CAST((FILEPROPERTY(name, 'SpaceUsed')* 8)/1024 AS numeric(10,2))

    FROM sysfiles

    SELECT @banco, @tamanho

    Andy

  • i think the question we should be asking Flavio is 'What do you want to do?' before we suggest any solution


    Everything you can imagine is real.

  • Dear All,

     

    I need to make a monthly control  on disk space on SQL 2000 Server. I have 3 servers.

    I thought to create a table and to insert the SELECT result in table.

     

    I don’t know very well SQL 2000 and DBA procedures.

    If somebody knows some procedure to make it, please help me.

     

    *****Replay to David A. Long

    Your select is returning only one record (Log file) . I would like seeing all records this table, but, it´s very good.

    Thank you

  • See if this article helps. 

    http://www.sqlservercentral.com/columnists/mnash/monitoringdriveanddatabasefreespace.asp

    My hovercraft is full of eels.

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

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