Quantcast
Channel: Desktop topics
Viewing all articles
Browse latest Browse all 213819

Creating table like sql trigger in Power BI ?

$
0
0

Hi all folks!

 

Here a little example of a sql trigger for creating and updating a table with fetch cycle in sql server:

 

/*inizio ciclo principale*/
DECLARE @AMBIENTE_max VARCHAR(50) ;
DECLARE @IDCOMPANY_max VARCHAR(50) ;
DECLARE @IDEMPLOY_max VARCHAR(50) ;
declare my_cursor_max cursor for select DISTINCT AMBIENTE, IDCOMPANY,IDEMPLOY from ZSW_TMP_EMPLOY_1 group by AMBIENTE, IDCOMPANY,IDEMPLOY;
open my_cursor_max;
FETCH NEXT FROM MY_CURSOR_max INTO @AMBIENTE_max,@IDCOMPANY_max,@IDEMPLOY_max;
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT 'Ambiente: '+RTRIM(CAST(@ambiente_max as VARCHAR(50)))
PRINT 'Azienda: '+RTRIM(CAST(@idcompany_max as VARCHAR(50)))
PRINT 'Dipendente: '+RTRIM(CAST(@idemploy_max as VARCHAR(50)))

/*ciclo interno per ogni singolo dipendente */
DECLARE @AMBIENTE VARCHAR(50) ;
DECLARE @IDCOMPANY VARCHAR(50) ;
DECLARE @IDEMPLOY VARCHAR(50) ;
DECLARE @DATA_INIZIO DATETIME ;
DECLARE @DATA_FINE DATETIME ;
DECLARE @PREV_DATA_INIZIO DATETIME;
SET @PREV_DATA_INIZIO = NULL;
declare my_cursor cursor for select DISTINCT AMBIENTE, IDCOMPANY,IDEMPLOY,DATA_INIZIO, DATA_FINE from ZSW_TMP_EMPLOY_1 where AMBIENTE=@AMBIENTE_max and IDCOMPANY=@IDCOMPANY_max and IDEMPLOY=@IDEMPLOY_max ORDER BY DATA_INIZIO DESC;
open my_cursor;
FETCH NEXT FROM MY_CURSOR INTO @AMBIENTE,@IDCOMPANY,@IDEMPLOY,@DATA_INIZIO, @DATA_FINE;
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT 'DATA INIZIO: '+RTRIM(CAST(@DATA_INIZIO as VARCHAR(50)))
PRINT 'DATA PRECEDENTE INIZIO: '+RTRIM(CAST(@PREV_DATA_INIZIO as VARCHAR(50)))
PRINT 'DATA FINE: '+RTRIM(CAST(@DATA_FINE as VARCHAR(50)))
UPDATE ZSW_TMP_EMPLOY_1 SET DATA_FINE=@PREV_DATA_INIZIO WHERE AMBIENTE=RTRIM(@AMBIENTE) AND IDCOMPANY=RTRIM(@IDCOMPANY) AND IDEMPLOY=RTRIM(@IDEMPLOY) AND DATA_INIZIO=@DATA_INIZIO;
SET @PREV_DATA_INIZIO = CAST(@DATA_INIZIO-1 AS DATETIME);
FETCH NEXT FROM MY_CURSOR INTO @AMBIENTE,@IDCOMPANY,@IDEMPLOY,@DATA_INIZIO, @DATA_FINE;
END
CLOSE MY_CURSOR;
DEALLOCATE MY_CURSOR;
/* fine ciclo interno*/
FETCH NEXT FROM MY_CURSOR_max INTO @AMBIENTE_max,@IDCOMPANY_max,@IDEMPLOY_max;
END
CLOSE MY_CURSOR_max;
DEALLOCATE MY_CURSOR_max;
/*fine ciclo principale*/

/*aggiorno tutte le date di fine nulle con data fine= '2999-12-31'*/
UPDATE ZSW_TMP_EMPLOY_1 SET DATA_FINE='29991231' WHERE DATA_FINE IS NULL

 

Is possible in POWER BI  create a similiar procedure?

 

Thanks a lot for your response...


Viewing all articles
Browse latest Browse all 213819

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>