第一张表:
+---------+------------------------+-----------+
| TableId | TableName | DatabaseName
+---------+------------------------+-----------+
| 1 | test | mydb |
+---------+------------------------+-----------+
第二张表:
+--------------------------------+
| ColID TableId ColName DataType |
+--------------------------------+
| 1 1 Amount Numeric
| 2 1 Name String |
+--------------------------------+
查询
SELECT *
(CASE data_type
WHEN 'NUMERIC' THEN 'SUM'
WHEN 'STRING' THEN 'LENGTH'
END) Operation_Performed,
(CASE data_type
WHEN 'NUMERIC' THEN (select sum(ColName ) from FirstTable.DatabaseName.FirstTable.TableName)
WHEN 'STRING' THEN (select length(ColName ) from FirstTable.DatabaseName.FirstTable.TableName)
END) Output
FROM
FirstTable tab
INNER JOIN
SecondTable col ON tab.table_id = col.table_id
在then子句的第二个case语句中,我需要使值动态但不解析。
还有其他方法吗?我无法使用存储过程。