Home > Forum > Rules, JS, SQL > ##currentloginname## in SQL filter for Report gives error

##currentloginname## in SQL filter for Report gives error
1

I'm struggling with the syntax of the SQL filter for a report.
In general it works, but if I want to use the currently loggedin user, I get an error.
I tried with the following syntax:

AND (##currentloginname##='servr\Userxxx')

The error message is:
"Incorrect syntax near '='. Incorrect syntax near ','. Incorrect syntax near the keyword 'order'."

MVP

Hi Klaus,


there's a simple issue in your query, the variable needs to be enclosed in '':

Before: AND (##currentloginname##='servr\Userxxx')
After: AND ('##currentloginname##'='servr\Userxxx')

Unfortunately there's a small issue with the variables:
Once the report is saved a space character is added at the end
Before save: AND ('##currentloginname##'='servr\Userxxx')
After save: AND ('##currentloginname## '='servr\Userxxx')

You can work around this issue with the following
and (RTrim('##currentloginname##') = 'server\user')

Best regards,
Daniel

Did you know that with WEBCON you can automate virtually any process? Even baking cookies 🍪
 
Speaking of cookies: we use the ones that are essential for our website to function properly, as well as additional ones that help us customize our content to your preferences. If you don’t mind cookies, click Accept. If you want to learn more, explore settings.
Settings