Forum Discussion

LeaRupnik's avatar
LeaRupnik
Helper III
6 years ago
Solved

how to create temp table with same sample like table on base

Hello. 

A have a one problem in SQL i now how to solve the case, bat in power bi i a new. 

I hawe a sql statment how to this do in power bi: 

 

WITH TEMP (PARENT_ID, ID, i) AS -- tempory table
(
SELECT
    PARENT_ID,
    ID,
    1
FROM
    DW.ORGANIZACIJA -- table on the base
WHERE
    PROGENOT IN (SELECT DISTINCT PROGENOT FROM DW.PAKIRANO) -- table on the base
UNION ALL
SELECT
    A.PARENT_ID,
    A.ID,
    i + 1
FROM
    DW.ORGANIZACIJA A, -- table on the base
    TEMP T
WHERE
    T.PARENT_ID=A.ID
    AND A.PARENT_ID IS NOT NULL
    AND i < 1000
)
SELECT
    DISTINCT
    'SISTEMIMPOL' CONCAT ORG1.PROGENOT as parent_id,
    ORG1.ORGENOTA AS PARENT,
    'SISTEMIMPOL' CONCAT ORG2.PROGENOT as child_id,
    ORG2.ORGENOTA AS CHILD,
    TEMP.PARENT_ID AS RAZVRSTI_PARENT_ID,
    TEMP.ID AS RAZVRSTI_CHILD_ID
FROM
    TEMP
    INNER JOIN DW.ORGANIZACIJA AS ORG1 ON TEMP.PARENT_ID=ORG1.ID
    INNER JOIN DW.ORGANIZACIJA AS ORG2 ON TEMP.ID=ORG2.ID
ORDER BY
    RAZVRSTI_PARENT_ID,
    RAZVRSTI_CHILD_ID
;

 

 

Thanks. 

Lea

  • Hi LeaRupnik ,

    Does that make sense? If so, kindly mark my answer as the solution to close the case please. More people will benefit from here. Thanks in advance.

     

    Best Regards,

    Xue Ding

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

4 Replies