Been looking at this from different dngles and read multiple post but still cant get this right. Can someone provide some guidance/help? Please, Thank you!
Trying to run this in Synapse and getting errors due to the incompatible FOR XML PATH near the end. This is a code that handles table metadata for imports. The last column will stuff the number of columns into a single line so the it can be used in a code run in sql.
SELECT source_system_table_metadata.*,
CASE
WHEN full_load = 'Y' THEN 'Truncate Table ' + target_schema + '.'
+ target_table
ELSE 'Delete from ' + target_schema + '.'
+ target_table + ' Where '
+ target_filter_column_name + ' > '''
+ source_filter_column_value + ''''
END AS Target_Table_Pre_SQL,
CASE
WHEN full_load = 'Y' THEN 'Where 1=1'
ELSE 'Where ' + source_filter_column_name + '>' + ''''
+ source_filter_column_value + ''''
END Source_Table_Filter,
CASE
WHEN col_list IS NULL THEN '*'
ELSE replace(col_list,'"','')
END col_list
FROM [gp].[source_system_table_metadata]
CROSS apply
(SELECT Stuff(
(SELECT
','
+ CONVERT(VARCHAR(200), source_column +
' as '
+
source_column_alias)
FROM [gp].[source_system_column_metadata]
WHERE
source_system_table_metadata.metadata_table_id =
source_system_column_metadata.metadata_table_id
FOR xml path(''), type
).value('.', 'VARCHAR(MAX)' ), 1, 1, ''
) AS col_list
)table_columns
Where isnull(active_status,'N') = 'Y'
Have the code run and concatenate the Stuff in the last piece correctly in Synapse