I'm trying to set the columnName, databaseName, schemaName etc. dynamically based on a temporary table but cant seem to make it work. i've tried below?
Create Table #test(databaseName varchar(128), schemaName varchar(128), columnName varchar(128), datatypeName varchar(128));
INSERT INTO #test ('testDatabase', 'testSchema', 'testTable', 'priceColumn');
SELECT
Case
WHEN DataType = 'int'
THEN SELECT MAX(ColumnName) FROM Concat(databaseName, '.', schemaName, '.', tableName)
ELSE 0
end
FROM #test;
DROP TABLE #test;
the expected result is that this below subquery take each line in the row in #test table and then query based on these values so it return the maxPrice from that table
SELECT MAX(ColumnName) FROM Concat(databaseName, '.', schemaName, '.', tableName)