Cursors in Fabric Warehouse
Hi everyone,
Could you please assist. I am trying to use a cursor in a Fabric datawarehouse.
The query is working fine on an on-prem SQL server, but It gives an error @@FETCH_STATUS not supported.
The question is: Can we use cursors in a Fabric Warehouse ? If not what is the alternative?
What I am trying to do here is to union all my cloned tables and then return then in one query. The tables are shown below. I just want to see if its possible.
Below is the code: (You can change the '%demo_test_clone%' to any table you have on your warehouse.
declare @SqlCommand as nvarchar(max)
declare @TableName as varchar(50)
declare @int as integer
set @int = 1
declare CloneTables CURSOR FOR select name from sys.tables where name like '%demo_test_clone%'
Open CloneTables
fetch next from CloneTables into @TableName
while @@fetch_Status = 0
begin
if @int = 1
begin
set @SqlCommand = concat('select * from ', @TableName)
set @int = 2
end
else
set @SqlCommand = concat(@SqlCommand, concat('union all ', @TableName))
fetch next from CloneTables into @TableName
end
Close CloneTables
Deallocate CloneTables
EXEC sp_executesql @SqlCommand
0
4 comments
Sonia Botha
1
Cursors in Fabric Warehouse
Learn Microsoft Fabric
skool.com/microsoft-fabric
Helping passionate analysts, data engineers, data scientists (& more) to advance their careers on the Microsoft Fabric platform.
Leaderboard (30-day)
Powered by