I have a dynamic query which works fine in SSMS meaning the columns are fetched using the below query in SSMS.
DECLARE @s NVARCHAR(MAX) = NULL
DECLARE @tablename NVARCHAR(500) = '@{pipeline().parameters.table_name}'
DECLARE @watermark NVARCHAR(1000) = '@{pipeline().parameters.watermark}'
DECLARE @period_back_from_utcnow NVARCHAR(500) = '@{pipeline().parameters.period_back_from_utcnow}'
SELECT @s = ISNULL(@s + ', ', '') + '[' + c.name + ']' + ' as [' + REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(c.name, ' ', '_'), '(', ''), ')', ''), '.', ''), '/', '') + ']'
FROM sys.all_columns c
JOIN sys.views t ON c.object_id = t.object_id
WHERE t.name = @tablename
SELECT CONCAT('SELECT ', @s, ' FROM ', @tablename) AS Query
As we can clearly see that Select statment has not been getting any columns in it. I tried to change the parameters with different types of concatenation and encapsulations but no luck. I tried to change the tablename variable declaration as below . Eventhough the input json could be created as above mentioned but with single quotes but no columns were being fetched in the SQL in Expression builder:
note : The connections and linked services are correct and no problem with them.
I tried to change the parameters with different types of concatenation and encapsulations but no luck. I tried to change the tablename variable declaration as below . Eventhough the input json could be created as above mentioned but with single quotes but no columns were being fetched in the SQL in Expression builder:
Expectation : Any insights on how to handle the tables from SQL Server database which has whitespaces in it. The above mentioned script working perfectly fine when the table names doesn't have any white spaces like if it's Currency_table, it would have worked.
Any insights on how to handle the tables from SQL Server database which has whitespaces in it.
If your Object name (table name, column name, procedure name, etc.) contain spaces then you need to eclosed it in the []
.
you can use below expression to add []
around the table name.
@{concat('[',pipeline().parameters.table_name,']')}
Here I tried similar expression in lookup query.
Providing parameter value as table name with space.
Getting proper result.