usql icon indicating copy to clipboard operation
usql copied to clipboard

Dynamically passing Table name as parameter in Stored Procedure in U-SQL

Open HermeetB opened this issue 7 years ago • 1 comments

I want to pass the Table name as in-parameter in a stored procedure in U-SQL and then want to have a SELECT * FROM the table. Something like below ::

USE DATABASE ADLDEMO;

CREATE PROCEDURE IF NOT EXISTS sp_demo (@TargetTableName string) AS BEGIN;

@a= SELECT * FROM @TargetTableName;

OUTPUT @a TO "/ADL-Demo/viewmultiple.csv" USING Outputters.Csv(outputHeader:true);

END;

but this is giving me error like "Rowset variable @TargetTableName was not found in the procedure 'sp_demo'."

can anyone please help on how to do select * from a table passed as in-parameter?

HermeetB avatar Apr 10 '18 04:04 HermeetB

Hi Hermeet

U-SQL (like any other SQL dialect) currently does not support table name parameterizations.

The current workaround is to generate the script either via PowerShell, T4, or another U-SQL Script (depending on how you get the parameter values and what your preferred workflow is), and then submit that generated script.

MikeRys avatar Apr 10 '18 18:04 MikeRys