Update script

  • Hi,

    I a mtrying to create update staments including data for the table in this way but I am getting error

    Incorrect syntax near '+'.

    Can anyone tell me whats wrongs in this script?

    SELECT 'UPDATE table_1

    SET labeltext ='+ T.labeltext

    'WHERE LanguageID = 10

    AND LabelKey ='+ T.LabelKey

    'AND FileID =' + T.FileID

    _______________________________________________________________
    To get quick answer follow this link:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

  • SELECT 'UPDATE table_1

    SET labeltext ='+ T.labeltext +

    'WHERE LanguageID = 10

    AND LabelKey ='+ T.LabelKey +

    'AND FileID =' + T.FileID

    Try this one. You are forgetting one "+" on the right side of LabelKey and labeltext.

  • sqlnaive (9/30/2013)


    SELECT 'UPDATE table_1

    SET labeltext ='+ T.labeltext +

    'WHERE LanguageID = 10

    AND LabelKey ='+ T.LabelKey +

    'AND FileID =' + T.FileID

    Try this one. You are forgetting one "+" on the right side of LabelKey and labeltext.

    still getting error:

    The multi-part identifier "T.labeltext" could not be bound.

    Msg 4104, Level 16, State 1, Line 4

    The multi-part identifier "T.LabelKey" could not be bound.

    Msg 4104, Level 16, State 1, Line 5

    The multi-part identifier "T.FileID" could not be bound.

    _______________________________________________________________
    To get quick answer follow this link:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

  • can you put your code in more details?

    What are these T.labeltext , T.LabelKey, T.FileID.

    error message is clear

  • SrcName (9/30/2013)


    can you put your code in more details?

    What are these T.labeltext , T.LabelKey, T.FileID.

    error message is clear

    SELECT 'UPDATE table_1 T

    SET labeltext ='+ T.labeltext

    'WHERE LanguageID = 10

    AND LabelKey ='+ T.LabelKey

    'AND FileID =' + T.FileID

    _______________________________________________________________
    To get quick answer follow this link:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

  • kapil_kk (9/30/2013)


    SrcName (9/30/2013)


    can you put your code in more details?

    What are these T.labeltext , T.LabelKey, T.FileID.

    error message is clear

    SELECT 'UPDATE table_1 T

    SET labeltext ='+ T.labeltext

    'WHERE LanguageID = 10

    AND LabelKey ='+ T.LabelKey

    'AND FileID =' + T.FileID

    SELECT 'UPDATE table_1 T

    SET labeltext ='+ T.labeltext +

    'WHERE LanguageID = 10

    AND LabelKey ='+ T.LabelKey +

    'AND FileID =' + T.FileID

    FROM You_Need_A_Source AS T

    The SQL Guy @ blogspot[/url]

    @SeanPearceSQL

    About Me[/url]

  • Sean Pearce (9/30/2013)


    kapil_kk (9/30/2013)


    SrcName (9/30/2013)


    can you put your code in more details?

    What are these T.labeltext , T.LabelKey, T.FileID.

    error message is clear

    SELECT 'UPDATE table_1 T

    SET labeltext ='+ T.labeltext

    'WHERE LanguageID = 10

    AND LabelKey ='+ T.LabelKey

    'AND FileID =' + T.FileID

    SELECT 'UPDATE table_1 T

    SET labeltext ='+ T.labeltext +

    'WHERE LanguageID = 10

    AND LabelKey ='+ T.LabelKey +

    'AND FileID =' + T.FileID

    FROM You_Need_A_Source AS T

    Hi,

    Try with this

    SELECT 'UPDATE table_1 T

    SET labeltext ='''+ T.labeltext +

    ''' WHERE LanguageID = 10

    AND LabelKey ='''+ T.LabelKey +

    ''' AND FileID =''' + T.FileID + ''''

    FROM You_Need_A_Source AS T

  • parulprabu (9/30/2013)


    Sean Pearce (9/30/2013)


    kapil_kk (9/30/2013)


    SrcName (9/30/2013)


    can you put your code in more details?

    What are these T.labeltext , T.LabelKey, T.FileID.

    error message is clear

    SELECT 'UPDATE table_1 T

    SET labeltext ='+ T.labeltext

    'WHERE LanguageID = 10

    AND LabelKey ='+ T.LabelKey

    'AND FileID =' + T.FileID

    SELECT 'UPDATE table_1 T

    SET labeltext ='+ T.labeltext +

    'WHERE LanguageID = 10

    AND LabelKey ='+ T.LabelKey +

    'AND FileID =' + T.FileID

    FROM You_Need_A_Source AS T

    Hi,

    Try with this

    SELECT 'UPDATE table_1 T

    SET labeltext ='''+ T.labeltext +

    ''' WHERE LanguageID = 10

    AND LabelKey ='''+ T.LabelKey +

    ''' AND FileID =''' + T.FileID + ''''

    FROM You_Need_A_Source AS T

    This assumes that T.LabelKey & T.FileID are character fields. If not then they will have to be CAST to VARCHAR.

    Kurt

    Kurt W. Zimmerman
    SR DBA
    Lefrak Organization
    New York, NY

    http://www.linkedin.com/in/kurtwzimmerman

  • Thanks a lot guys for your help....

    I have created the script now :-D:-P

    _______________________________________________________________
    To get quick answer follow this link:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

  • SELECT 'UPDATE table_1

    SET labeltext ='+ T.labeltext +

    from tableName T(Need Here)

    'WHERE LanguageID = 10

    AND LabelKey ='+ T.LabelKey +

    'AND FileID =' + T.FileID

  • The elephant on the carpet here of course is that the next statement in line is going to be:

    EXEC (@UpdateScript)

    And that is going to be highly prone to SQL injection. Using sp_executesql with parameters passed in is going to be much safer.


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St

  • dwain.c (10/8/2013)


    The elephant on the carpet here of course is that the next statement in line is going to be:

    EXEC (@UpdateScript)

    And that is going to be highly prone to SQL injection. Using sp_executesql with parameters passed in is going to be much safer.

    +1 to that. Hello "Little Bobby Tables"! 😉

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 12 posts - 1 through 11 (of 11 total)

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