Not Familiar with this Syntax: Are these aliases? (Easy)

  • I've seen aliases used similarly. Is this the same? Its from a system stored proc so I could not run it.

    Is 'Type_name' and 'Storage_type' simply aliases? So the query could be rewritten with as and alias name at the end right? I think I studied this before, but its been so long since i seen it, I just want to make sure. If it was using easily identifiable column names I'd be more sure. Thanks

    select

    'Type_name'= name,

    'Storage_type'= type_name(system_type_id),

    'Length'= max_length,

    'Prec'= Convert(int,TypePropertyEx(user_type_id, 'precision')),

    'Scale'= Convert(int,TypePropertyEx(user_type_id, 'scale')),

    'Nullable'= case when is_nullable=1 then @yes else @no end,

    'Default_name'= isnull(object_name(default_object_id), @none),

    'Rule_name'= isnull(object_name(rule_object_id), @none),

    'Collation'= collation_name

    from sys.types

    where user_type_id = @objid

    ALTERNATIVE?

    select

    name as 'Type_name',

    type_name(system_type_id) as 'Storage_type',

    max_length as 'Length',

    Convert(int,TypePropertyEx(user_type_id, 'precision')) 'Prec',

    from sys.types

    where user_type_id = @objid

  • Yes it just another way to alias a column. 😀

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • It's a non-standard use though. I don't know that I'd actively rewrite everything I found that way, but I'd certainly discourage any new code being written like that.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Grant Fritchey (3/5/2014)


    It's a non-standard use though. I don't know that I'd actively rewrite everything I found that way, but I'd certainly discourage any new code being written like that.

    +1

    I thought that particular notation has been on the deprecated list for some time. Get rid of any instances of this before they pull the plug and just flat out stop supporting the notation.

    From BOL's 2012 list of deprecated features:

    String literals as column aliases

    Syntax that contains a string that is used as a column alias in a SELECT statement, such as 'string' = expression, was encountered. Do not use. Occurs once per compilation

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • So you guys suggest I should avoid that syntax? Ok

    I got it from doing debug on the following statement:

    EXEC sp_help;

    GO

  • Jacob Pressures (3/5/2014)


    So you guys suggest I should avoid that syntax? Ok

    I got it from doing debug on the following statement:

    EXEC sp_help;

    GO

    Ha! Awesome. That would explain why it's not yet removed from the product. Microsoft still hasn't fixed all their own code.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • LOL!!!

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

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