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) = '

 

 

 

&CUR_DATE.EVAL




',
@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) ='

 

 

&&STU_LNAME.EVAL


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

Not sure I understand the code you've psoted, but looks like you were trying to get "Current Date" into each row, and for it to be the exact time of each rows' update, rather than the same DateTime for every row in the batch (which is what SQL does).

Dunno if it helps, but you can do something like this:

DECLARE @MyOffset int = 1
UPDATE Templates 
SET stringtemplate = @stringtemplate + CONVERT(varchar(20), @MyOffset)
    , @MyOffset = @MyOffset + 1
FROM [Test].[dbo].[Templates] Templates 
WHERE milestone_code = @milestone 
AND language = @language

which will give you an increment-value on each row. Lots of opportunity to use other expressions in the @MyOffset assignment, so maybe you can create the type of value you want - e.g. add 100 ms to a DateTime value each iteration, or something like that.

1 Like