Table Variables in Workbench

I have the following snippet of SQL code that I'm testing in Domo Workbench, basically just populating a table variable with one row for each of the previous 18 months. Domo Workbench (3.1.5714.35059) will validate the code, but I can't get it to preview. When I click the Preview button, I see messages that the query executed, etc, but the preview is never shown. No error messages, no nothing.

 

declare @pds table (
EvtMo smallint
,EvtYr int
)


declare @tmpDate date = getdate()
while datediff(month,@tmpDate,getdate()) < 18
begin
insert into @pds select datepart(month,@tmpdate), datepart(year,@tmpDate)
set @tmpDate = dateadd(month,-1,@tmpDate)
end

select * from @pds

Best Answers

  • PEAKS_valleys
    PEAKS_valleys Member
    Answer ✓

    Hey Chris - 

     

    Maybe I'm missing exactly what you're trying to do but can you create the final table outside of Domo and then import? You could use MySQL or PostreSQL interface to run the join of the datasets. 

     

    Or, you could import both datasets and join them using a MySQL dataflow in Domo. 

     

    - Aaron

  • northshorehiker
    Answer ✓

    Hi Adam--

     

    Thanks for your message. I finally managed to figure this out... I had a stored proc (my back-end is SQL Server) that gave me exactly the dataset I needed, using a table variable for the table of months... I've since created a physical table of months that I'm now using instead, and Domo Workbench is handling that just fine.

     

    It sounds weird, but for some reason, I only realized that option while reading your last message, so thanks for that. =^)

     

    ==

    Chris

Answers

  • kshah008
    kshah008 Contributor

    Hi all,

     

    Can anybody help @northshorehiker out?

    Thanks!

  • Or even if I could find out what the "dos and don'ts" are, for the SQL code being run by the Domo Workbench... It looks like table variables and temp tables aren't acceptable... can someone confirm this? Are there any more of these types of "gotchas"?

  • Hey @northshorehiker - 

     

    I don't think that you can pass a table variable as in input, it doesn't work like a create table function. 

     

    Have you tried using the transforms available in workbench to get the dates you're looking for? Or, have you tried importing the table and creating a MySQL dataflow within Domo?

     

    The workbench documentation is pretty good, take a look here

     

    Hope this helps! 

  • Thank you for your response.

     

    My apologies, I probably should've included this in my initial message.,,, Ultimately, what I need to do is upload a dataset that contains one row for each of the past 18 months, along with some figures for each month. For some months, there will be no data, so it would just display zeroes in those rows.  So, I thought that starting with a table of the past 18 months and left joining it to a table of the data figures summarized by month would do the trick, (and does, in a stored procedure) but I can't figure out how to get it to Domo workbench in a method that's acceptable.  Thank you for the Workbench documentation link; I'll take a look at that.

     

    ==
    Chris

  • PEAKS_valleys
    PEAKS_valleys Member
    Answer ✓

    Hey Chris - 

     

    Maybe I'm missing exactly what you're trying to do but can you create the final table outside of Domo and then import? You could use MySQL or PostreSQL interface to run the join of the datasets. 

     

    Or, you could import both datasets and join them using a MySQL dataflow in Domo. 

     

    - Aaron

  • northshorehiker
    Answer ✓

    Hi Adam--

     

    Thanks for your message. I finally managed to figure this out... I had a stored proc (my back-end is SQL Server) that gave me exactly the dataset I needed, using a table variable for the table of months... I've since created a physical table of months that I'm now using instead, and Domo Workbench is handling that just fine.

     

    It sounds weird, but for some reason, I only realized that option while reading your last message, so thanks for that. =^)

     

    ==

    Chris

  • Sweet, glad you got this squared away!

  • Hi,

     

    I'm working exactly on the same business requirement. The data sits in Salesforce, and I'm using a connector to pull it into Domo and then manipulate it. But, the problem is , I'm trying to create a dataflow to run stored procedure. However, Domo wouldn't execute the code and keeps throwing an error at variable declaration in the procedure. 

     

    Following is the code, I've used: Could you help me figure out what I'm missing here, or something that has worked for you :

     

    drop procedure if exists load_foo_test_data;

    delimiter $$
    create procedure load_foo_test_data()
    BEGIN

    Set @v_max = 13;
    Set @v_counter =1;

    start transaction;
    while `v_counter` < `v_max` do
    insert into cb_sf_masterdata (FinalRevenue) value(adjustedrevenue/13) ;
    set `v_counter`= `v_counter`+1;
    end while;
    commit;
    end; $$

    delimiter ;

     

     

    Thank you