How to use the SET function in table transformer

Bart Hoegaerts February 2, 2023

I'm trying to use the SET function in table transformer as described on
Using multiple SQL statements. Inserting new rows
Custom Transformation - use cases with advanced SQL queries (stiltsoft.com) 

I have created a simple table and where I want to add up 1 year per row on the date start; the added date to be set as end year.

this is the statement:
SET @count = 0,
SET @date = (SELECT T1.'Start' FROM T1),
WHILE @count < 15
BEGIN
SET @count = @count + 1,
SET @date = DATEADD(YEAR,1, @date),
INSERT INTO T1(T1.'End') VALUES (@date),
END
SELECT * FROM T1

but it returns an syntax error
SyntaxError: Parse error on line 1: SET @count = 0, SET @date -----^ Expecting 'LITERAL', 'BRALITERAL', got 'COUNT'

How do I use the SET function in table transformer? 
thanks!

1 answer

3 votes
Katerina Rudkovskaya _Stiltsoft_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
February 3, 2023

Hi @Bart Hoegaerts,

Please note some differences between your query and the query from our documentation:

Fri 8-1.png

SET @cnt = 0;
SET @date = (SELECT T1.'Start' FROM T1);
WHILE @cnt < 15
BEGIN
SET @cnt = @cnt + 1;
SET @date = FORMATDATE(DATEADD(YEAR,1,@date));
INSERT INTO T1 (T1.'End') VALUES (@date)
END;
SELECT * FROM T1

Fri 8-2.png

Here we use @cnt, not @count because COUNT is a special function and there may happen a conflict within the query. Also pay attention on the semicolons at the end of the lines (not commas).

Also here is a variant of a slightly more complex query to get rid of an empty cell in the result table:

Fri 8-3.png

UPDATE T1
SET T1.'End'=FORMATDATE(DATEADD(YEAR,1,'Start')) WHERE 'Start Mark'="Start";
SET @cnt = 0;
SET @date = (SELECT T1.'End' FROM T1);
WHILE @cnt < 15
BEGIN
SET @cnt = @cnt + 1;
SET @date = FORMATDATE(DATEADD(YEAR,1,@date));
INSERT INTO T1 (T1.'End') VALUES (@date)
END;
SELECT T1.'Start', T1.'End' FROM T1

Fri 8-4.png
Hope it helps.

Bart Hoegaerts February 3, 2023

Perfect ! this works well ! Thanks a lot !

Like # people like this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events