Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

SQL SET @Variable not resolved correctly in WHERE statement with Table Transformer

Kamil Graczyk
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 16, 2023

Hey Guys,
so basically I use this SQL statement to calculate the remainder of dividing the current week of the year by five:

SET @MYVAR = (FORMATDATE(GETDATE(), 'w') - (FLOOR(FORMATDATE(GETDATE(), 'w') / 5) * 5))

 

And when I try to use it with my table
eeee.png

Like this:

SELECT * FROM T1 WHERE 'person' = @MYVAR

It says "The query returned no rows."

What is the problem with that?
When I'm doing

SELECT @MYVAR FROM T1

It's resolved correctly.

1 answer

3 votes
Stiltsoft support
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 17, 2023

Hi @Kamil Graczyk ,

Maybe the following workaround will help your case:

Fri 12-1.png

Note that you will need the Table Toolbox macro to nest macros on Confluence Cloud.

Here are the settings of the internal Table Transformer macro:

Fri 12-2.png

SELECT *,
(FORMATDATE(GETDATE()) - FLOOR(FORMATDATE(GETDATE())/5)*5) AS 'weeks'
FROM T*

Fri 12-3.png

And here is the SQL query for the external Table Transformer macro:

SELECT 'value', 'person' FROM T*
WHERE 'value' = 'weeks'

Fri 12-4.png

Hope it will help your case.

Note that you've tried to compare numbers with the 'person' column that contains letters (strings). Seems that the 'value' is a correct field for the case.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events