Forum Discussion
Error in Script Activity with Script parameters
- 6 months ago
Hi Nejib,
You’re running into this because Script activity parameters can replace only values in a SQL/PGSQL statement, not identifiers (like schema, table, or column names). In other words:Works: using a parameter in predicates or values (e.g., WHERE status = @status).
Fails: trying to use a parameter where SQL expects an identifier (e.g., SELECT col FROM ... or FROM schema.@table). In those cases, the engine won’t substitute an identifier.If your screenshots show param inside the SELECT list or the FROM clause, that’s why it errors.
Option1:
If you want to use parameters in sql statement like select,drop,etc
use pipeline parametersOption 2:
If you want to use script parameters, you need to create SP
example:
create stored procedureCREATE OR ALTER PROCEDURE dbo.usp_select_from_any
schema_name sysname, @table_name sysname
AS
BEGIN
DECLARE sql nvarchar(max) =
N'SELECT * FROM ' + QUOTENAME(@schema_name) + N'.' + QUOTENAME(@table_name) + ';';
EXEC (@sql);
END;call it in script like:
EXEC dbo.usp_select_from_any
schema_name = schema_name,
@table_name = @table_name;
Thanks and Regards,
Shreya
Hi Nejib,
You’re running into this because Script activity parameters can replace only values in a SQL/PGSQL statement, not identifiers (like schema, table, or column names). In other words:
Works: using a parameter in predicates or values (e.g., WHERE status = @status).
Fails: trying to use a parameter where SQL expects an identifier (e.g., SELECT col FROM ... or FROM schema.@table). In those cases, the engine won’t substitute an identifier.
If your screenshots show param inside the SELECT list or the FROM clause, that’s why it errors.
Option1:
If you want to use parameters in sql statement like select,drop,etc
use pipeline parameters
Option 2:
If you want to use script parameters, you need to create SP
example:
create stored procedure
CREATE OR ALTER PROCEDURE dbo.usp_select_from_any
schema_name sysname, @table_name sysname
AS
BEGIN
DECLARE sql nvarchar(max) =
N'SELECT * FROM ' + QUOTENAME(@schema_name) + N'.' + QUOTENAME(@table_name) + ';';
EXEC (@sql);
END;
call it in script like:
EXEC dbo.usp_select_from_any
schema_name = schema_name,
@table_name = @table_name;
Thanks and Regards,
Shreya