t-sql 2012 declare variables issue

  • In t-sql 2012, I want to update the value in the column called stringtemplate in
    the table called Templates 26 times. I want to update this value uniquely since
    the value changes depending upon the row I am updating. I would like to use the
    same declare of @stringtemplate, @milestone, and @language without having to
    come up with other declare variables for the 26 rows. The sql I listed below
    does not work for
    even two rows in the table being updated. I have tried lots of different version
    of the sql, but nothing I have tried work. This can you show me the t-sql 2013
    that I can use to accomplish my goal?
    Use Test       Declare @stringtemplate varchar(max) = '<p>&nbsp;</p>  <p>&nbsp;</p> 
          <p>&nbsp;</p>  <p>&amp;CUR_DATE.EVAL</p>  <br />  <br />  <br />  <p> 
    </p>',
     @milestone varchar(10) = '005',
            @language varchar(10) = 'EN'
            UPDATE Templates
     SET stringtemplate = @stringtemplate
     FROM [Test].[dbo].[Templates] Templates
     WHERE milestone_code = @milestone
     AND language = @language set @stringtemplate varchar(max) ='<p>&nbsp;</p>
    <p>&nbsp;</p><p>&amp;&amp;STU_LNAME.EVAL</p>
    <br /> <br /> <br /> A los Padres de',
    @milestone varchar(10) = '010',
    @language varchar(10) = 'ES'
     UPDATE Templates
     SET stringtemplate = @stringtemplate
     FROM [Test].[dbo].[Templates] Templates
     WHERE milestone_code = @milestone
     AND language = @language

  • You can't use SET to set the values of several variables. You would either need to use SELECT, or SET the value of each one individually.

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk

  • Maybe something like this (?):


    CREATE TABLE #templates_update (
      stringtemplate varchar(max) NOT NULL,
      milestone varchar(10) NOT NULL,
      language varchar(10) NOT NULL
      )
    INSERT INTO #templates_update
    VALUES('<p>&nbsp;</p> <p>&nbsp;</p>
    <p>&nbsp;</p> <p>&amp;CUR_DATE.EVAL</p> <br /> <br /> <br /> <p>
    </p>',
    '005','EN' ),
      ('<p>&nbsp;</p>
    <p>&nbsp;</p><p>&amp;&amp;STU_LNAME.EVAL</p>
    <br /> <br /> <br /> A los Padres de',
    '010', 'ES')

    UPDATE Templates
    SET stringtemplate = TU.stringtemplate
    FROM [Test].[dbo].[Templates] Templates
    INNER JOIN #templates_update TU ON TU.milestone = Templates.milestone_code AND TU.language = Templates.language

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

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

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