Syntax errors

  • Hi,

    i am trying to execute below command but output is not getting .In my table year is 2017.
    can anyone help me

    SET @TableName = 'dbo.my_latestyear_ + CAST(@Year AS Varchar(4))_new'
        
        RETURN @TableName

    OutPut Come like --->my_latestyear_2017_new

    but output coming like  dbo.my__latestyear + CAST(@Year AS Varchar(4))_new

    please help me out.

  • Sree Divya - Tuesday, July 25, 2017 1:03 PM

    Hi,

    i am trying to execute below command but output is not getting .In my table year is 2017.
    can anyone help me

    SET @TableName = 'dbo.my_latestyear_ + CAST(@Year AS Varchar(4))_new'
        
        RETURN @TableName

    OutPut Come like --->my_latestyear_2017_new

    but output coming like  dbo.my__latestyear + CAST(@Year AS Varchar(4))_new

    please help me out.

    You need to close the quotes before adding the year, instead of after.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • SET @TableName = 'dbo.my_latestyear_' + CAST(@Year AS Varchar(4)) + '_new'

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • Sree Divya - Tuesday, July 25, 2017 1:03 PM

    Hi,

    i am trying to execute below command but output is not getting .In my table year is 2017.
    can anyone help me

    SET @TableName = 'dbo.my_latestyear_ + CAST(@Year AS Varchar(4))_new'
        
        RETURN @TableName

    OutPut Come like --->my_latestyear_2017_new

    but output coming like  dbo.my__latestyear + CAST(@Year AS Varchar(4))_new

    please help me out.

    DECLARE @tablename varchar(100)
    ,@Year varchar(4)
    SET @Year='1994'
    SET @TableName = 'dbo.my_latestyear_'+ CAST(@Year AS Varchar(4))+'_new'

    print @TableName

Viewing 4 posts - 1 through 3 (of 3 total)

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