How to use alias name ?

  • hi,

    My query is working fine but I just want to know how to change the result like eg,5,4,6 GB i want to see in this format how can we use alias name for this .

    select

    BackupDate = convert(varchar(10),backup_start_date, 111),server_name,name

    ,SizeInGigs=floor( backup_size/1024000000)

    from msdb..backupset

    where

    database_name = 'adventureworks'

    and type = 'd'

    order by

    backup_start_date desc

  • It's not an alias you're looking for but some formatting. Try changing to this:

    CAST(SizeInGigs=floor( backup_size/1024000000) AS VARCHAR) + ' GB'

    An alias is a way of masking or changing a column or table name:

    SELECT a.MyCol AS 'Dude'

    FROM GreatBigTableName AS a

    ----------------------------------------------------The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood... Theodore RooseveltThe Scary DBAAuthor of: SQL Server 2017 Query Performance Tuning, 5th Edition and SQL Server Execution Plans, 3rd EditionProduct Evangelist for Red Gate Software

  • Grant Fritchey (5/6/2008)


    It's not an alias you're looking for but some formatting. Try changing to this:

    CAST(SizeInGigs=floor( backup_size/1024000000) AS VARCHAR) + ' GB'

    An alias is a way of masking or changing a column or table name:

    SELECT a.MyCol AS 'Dude'

    FROM GreatBigTableName AS a

    jagpalsingh4 (5/6/2008)


    hi,

    My query is working fine but I just want to know how to change the result like eg,5,4,6 GB i want to see in this format how can we use alias name for this .

    Jeff,

    I think he wants single line of result with comma seperated. what you said is right but it will be seperate cells

  • shamshudheen (5/7/2008)


    Jeff,

    Who's Jeff?

    Ryan Randall

    Solutions are easy. Understanding the problem, now, that's the hard part.

  • Hi,

    Really thaxx to everybody i have done what i need

    select

    BackupDate = convert(varchar(10),backup_start_date, 111),server_name,name,database_creation_date

    , CAST((floor( backup_size/1024000000)) AS VARCHAR) + ' GB'as sizeinGB

    from msdb..backupset

    where

    database_name = 'adventureworks'

    and type = 'd'

    order by

    backup_start_date desc

    Regards

    Jagpal Singh

  • RyanRandall (5/7/2008)


    shamshudheen (5/7/2008)


    Jeff,

    Who's Jeff?

    sorry not jeff

    Ryan

    your understanding is right....

  • No, no, no. Jeff's smarter and better looking. I'm.... uh, I'm.... Hey!

    ----------------------------------------------------The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood... Theodore RooseveltThe Scary DBAAuthor of: SQL Server 2017 Query Performance Tuning, 5th Edition and SQL Server Execution Plans, 3rd EditionProduct Evangelist for Red Gate Software

  • Grant Fritchey (5/7/2008)


    No, no, no. Jeff's smarter and better looking. I'm.... uh, I'm.... Hey!

    hey.. i confused.. i was saying to Grant not jeff and not ryan

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

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