这是我之前关于如何在 SQL Server 中迭代字符串的问题:
现在我该如何专门选择列名?这是我选择列的代码:
SELECT 'Field '+CAST(ROW_NUMBER() OVER (ORDER BY ordinal_position) AS varchar(5))+': ' +
COLUMN_NAME
FROM information_schema.columns
WHERE table_Name = 'SystemDefined' and table_schema = 'schemaAsset'
这是输出:
Field 1: Asset_No
Field 2: AssetCategory
Field 3: AssetClassification
Field 4: PurchaseType
Field 5: Department
Field 6: RespPerson
Field 7: Status
Field 8: Location
这是我在选择特定列名时想要的输出:
Field 1: Asset_No
Field 2: AssetCategory
Field 3: AssetClassification
Field 4: PurchaseType
Field 5: Department
Field 6: RespPerson
Field 7: Status