Home > Forum > Database > Calculated Column - SQL Query from another workflow

Calculated Column - SQL Query from another workflow
0

Can I query SQL (WFDElements) to get a value for calculated column in the report from another workflow?
Alternatively is there any way to present an SQL query as a report? Or on dashboard?
I have a few cases where I need to pivot certain information. The only way until now that I found is to create a data source and a technical workflow that will load it into a table but it's far from perfect

Dear Patryk,
if I understand your question correctly, you can use wfelems (alias) in query.

Here is an example of the query I use to get value from another (related) workflow (in this case it's Signature) in calculated column (I use type text):

(
select WFD_Signature as Signature
from WFElements
where wfelems.WFD_WFDID = WFD_ID and WFD_DTYPEID = '<id of the form type>''
)

I also specify WFD_DTYPEID "filter" results for specific workflow.

Hope this helps you solve your case.

In reply to: Adam Hatak

Dear Patryk,
if I understand your question correctly, you can use wfelems (alias) in query.

Here is an example of the query I use to get value from another (related) workflow (in this case it's Signature) in calculated column (I use type text):

(
select WFD_Signature as Signature
from WFElements
where wfelems.WFD_WFDID = WFD_ID and WFD_DTYPEID = '<id of the form type>''
)

I also specify WFD_DTYPEID "filter" results for specific workflow.

Hope this helps you solve your case.

Thanks, it mostly works. The problem is that I can't filter by value of another column from the report.
So I have this report where I have employee column (WFD_Attchoose1) and for this employee I need to do the select. So in each row I need to reference this employee and I don't know how to do it, how to pass this value into the script.

(
SELECT SUM(WFD_AttDecimal1) AS TotalWorkingDays
FROM WFElements
WHERE WFD_AttChoose4 LIKE --- This I need to reference from report column so put per row value of AttChoose1 ---
AND WFD_STPID = 252
AND YEAR(WFD_AttDateTime2) = YEAR(GETDATE())
)

MVP
In reply to: Jacek Wojnar

Hi Patryk,
And just remember that WFD_STPID will be different for DEV/TEST/PROD environments (if you want to indicate a specific step you should use the GUID).

I'd say don't ever use ID in calculated columns - always go for GUID if you don't want to have broken views after every export/import to prod.

Here is updated query based on Krystians answer:

(
SELECT SUM(WFD_AttDecimal1) AS TotalWorkingDays
FROM WFElements
LEFT OUTER JOIN WFSteps ON STP_ID = WFD_STPID
WHERE WFD_AttChoose4 = wfelems.WFD_AttChoose1
AND STP_GUID = 'HERE THE GUID'
AND YEAR(WFD_AttDateTime2) = YEAR(GETDATE())
)