Sql server 如何对CTE创建的数据使用表值函数
我只是想使用一个表值函数,并用一个简单的CTE建立的数据对其进行测试,但是我无法弄清楚如何让表值函数“看到”CTE。我错过了什么Sql server 如何对CTE创建的数据使用表值函数,sql-server,common-table-expression,Sql Server,Common Table Expression,我只是想使用一个表值函数,并用一个简单的CTE建立的数据对其进行测试,但是我无法弄清楚如何让表值函数“看到”CTE。我错过了什么 /* The below shows that I can SELECT the CSVField from my CTE CSVData */ WITH CSVData AS ( SELECT 'a,b,f,hello,yup' as CSVField ) SELECT CSVField FROM CSVData ; /* This Works and
/* The below shows that I can SELECT the CSVField from my CTE CSVData */
WITH CSVData AS
(
SELECT 'a,b,f,hello,yup' as CSVField
)
SELECT CSVField FROM CSVData
;
/* This Works and produces a table of the CSV Values */
SELECT * FROM dbo.Split('a,b,f,hello,yup', ',')
/* Does NOT Work: The below for whatever reason the TVF can't see the CTE as if it's not in Scope or for some other reason */
WITH CSVData AS
(
SELECT 'a,b,f,hello,yup' as CSVField
)
SELECT c.* FROM dbo.Split(CSVData.CSVField, ',') c
;
表输出示例
你可以这样写
使用CSVData作为
选择“a、b、f、helloWorld、YesSir”作为CSVField
选择c*
从dbo.Split中选择CSVField FROM CSVData,,'c
;