我有 2 个查询,其中一个查询包含另一个查询要使用的参数。我做了类似的事情,但没有使用多个参数。以下是查询:
SELECT [loadJob]
,[loadStep]
,[parameter]
,[value]
FROM [Admin].[admin].[LoadParameters] where loadJob like 'someJobName%' and (parameter = 'targetDatabaseName' or parameter = 'targetDatasetName' or parameter = 'targetDatasetSchema')
SELECT
TABLE_CATALOG as DB,
TABLE_SCHEMA,
TABLE_NAME,
COLUMN_NAME,
ORDINAL_POSITION,
COLUMN_DEFAULT,
IS_NULLABLE,
DATA_TYPE,
CHARACTER_MAXIMUM_LENGTH,
NUMERIC_PRECISION,
NUMERIC_PRECISION_RADIX,
NUMERIC_SCALE,
DATETIME_PRECISION,
CHARACTER_SET_NAME
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_CATALOG = 'TheDataBase' // From the [parameter] with name 'targetDatabaseName' get form the [value] column
AND TABLE_SCHEMA = 'data' // From the [parameter] with name 'targetDatasetSchema' get form the [value] column
AND TABLE_NAME = 'TableName' // From the [parameter] with name 'targetDatasetName' get form the [value] column
所以如果我的第一个查询结果是:
[parameter] [value]
targetDatabaseName SomeDataBaseName
targetDatasetSchema data
targetDatasetName TheTableName
第二个查询中的 where 子句将使用这些参数,如下所示:
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_CATALOG = 'SomeDataBaseName'
AND TABLE_SCHEMA = 'data'
AND TABLE_NAME = 'TheTableName'
我也想按表名对所有内容进行分组,以便将其导出为 CSV。我尝试了一些东西,但我可以自豪地说什么都行不通。