T-SQL

  • Anju Renjith

    Ten Centuries

    Points: 1135

    Comments posted to this topic are about the item T-SQL

  • erwin oosterhoorn

    SSCrazy

    Points: 2009

    Nice and easy...

  • l.vignando

    Old Hand

    Points: 313

    I tried on Sql 2005,

    Msg 139, Level 15, State 1, Line 0

    Cannot assign a default value to a local variable.

    Msg 137, Level 15, State 2, Line 4

    Must declare the scalar variable "@str1".

    Am I testing it in a wrong way?

  • SALIM ALI

    Right there with Babe

    Points: 799

    the answer is only correct when using SqlServer 2012 and above. Previous versions prompt an error.

  • erwin oosterhoorn

    SSCrazy

    Points: 2009

    l.vignando (12/19/2014)


    I tried on Sql 2005,

    Msg 139, Level 15, State 1, Line 0

    Cannot assign a default value to a local variable.

    Msg 137, Level 15, State 2, Line 4

    Must declare the scalar variable "@str1".

    Am I testing it in a wrong way?

    if you try this on 2005 you will need to split the variable assignment, try this:

    @str1 VARCHAR(5)

    ,@str2 VARCHAR(10) ;

    select @str1 = NULL, @str2 = 'SQL Strings';

  • Anju Renjith

    Ten Centuries

    Points: 1135

    I use SQL Server 2008 R2 and it works fine..

  • serg-52

    SSCrazy Eights

    Points: 9802

    SALIM ALI (12/19/2014)


    the answer is only correct when using SqlServer 2012 and above. Previous versions prompt an error.

    2008 is quite enough.

  • Raghavendra Mudugal

    SSChampion

    Points: 10658

    erwin.oosterhoorn (12/19/2014)


    l.vignando (12/19/2014)


    I tried on Sql 2005,

    Msg 139, Level 15, State 1, Line 0

    Cannot assign a default value to a local variable.

    Msg 137, Level 15, State 2, Line 4

    Must declare the scalar variable "@str1".

    Am I testing it in a wrong way?

    if you try this on 2005 you will need to split the variable assignment, try this:

    @str1 VARCHAR(5)

    ,@str2 VARCHAR(10) ;

    select @str1 = NULL, @str2 = 'SQL Strings';

    In-line assignment was introduced in version SQL 2008

    DECLARE

    {

    { @local_variable [AS] data_type | [ = value ] }

    | { @cursor_variable_name CURSOR }

    } [,...n]

    Prior to SQL 2008, declaration and assignment happens in two different lines.

    ww; Raghu
    --
    The first and the hardest SQL statement I have wrote- "select * from customers" - and I was happy and felt smart.

  • Ed Wagner

    SSC Guru

    Points: 286958

    While yes, initial assignment was introduced in SQL 2008, I think the point of the question was what it prints out and the data types involved. I thought it was a good question that raised a good point.

  • This was removed by the editor as SPAM

  • Mike Hays

    SSCommitted

    Points: 1871

    Interesting Question, thanks!

  • stephen.long.1

    SSCrazy

    Points: 2568

    Nice simple question, thanks.

  • Dana Medley

    SSCertifiable

    Points: 6764

    Thanks for the question. Good way to start Friday.



    Everything is awesome!

  • Thomas Abraham

    SSChampion

    Points: 10761

    Nice easy one for a Friday. Thanks for submitting the question!

    [font="Verdana"]Please don't go. The drones need you. They look up to you.[/font]
    Connect to me on LinkedIn

  • Miles Neale

    SSChampion

    Points: 13147

    I overthought this one but still got it right. Nice question.

    Not all gray hairs are Dinosaurs!

Viewing 15 posts - 1 through 15 (of 24 total)

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