三个 CTE 问题
我希望做这样的事情:
WITH Hello (Name)
AS (
INSERT INTO MyTest
OUTPUT
inserted.Name
VALUES ('George')
)
SELECT * FROM Hello
简而言之,我希望输出只是成为 CTE 输入。有办法解决这个问题吗?
还有两个问题:
- 有没有办法构造一个空的CTE?
- CTE 可以修改吗?我可以在构建后插入行吗?
更新 我找到了主要问题的答案,目的是用任意数据填充 CTE:
;WITH stuff AS (
SELECT * FROM ( VALUES
(123, 1),
(234, 1),
(345, 0)
) [X](id, pref)
)
SELECT * FROM stuff
I was hoping to do something like this:
WITH Hello (Name)
AS (
INSERT INTO MyTest
OUTPUT
inserted.Name
VALUES ('George')
)
SELECT * FROM Hello
In short, I was hoping the output would simply become the CTE input. Is there a way to fix this?
Two more questions:
- Is there a way to construct an empty CTE?
- Can a CTE be modified? Can I insert rows after it has been constructed?
UPDATE
I found the answer to my primary question, with the intent of filling a CTE with arbitrary data:
;WITH stuff AS (
SELECT * FROM ( VALUES
(123, 1),
(234, 1),
(345, 0)
) [X](id, pref)
)
SELECT * FROM stuff
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
另外两个问题
1)
2)
the two other questions
1)
2)