如何在一个CTE中使用两个select语句 [英] How to use a two select statement with one CTE
本文介绍了如何在一个CTE中使用两个select语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hello Every One,
我有以下代码请帮帮我
@RecordCount是存储过程中的输出参数
Hello Every One,
I have following code please help me out
@RecordCount is a output Parameter in Store Procedure
;WITH CTE AS
(
SELECT *
FROM TableName
)
Select @RecordCount = Count(*) from CTE
Select * from CTE
如何获得@RecordCount和所有选定的值
在第二个选择语句中有错误,如CTE不可用
在此先感谢..
How can i get a @RecordCount and all selected Value
There is an error like CTE is not available in second select statement
Thanks in advance..
推荐答案
您不需要CTE。
You don't need CTE.
DECLARE @rcount INT = 0
SELECT @rcount = COUNT(*)
FROM TableName
--it would return the count of records
SELECT @rcount AS RecordCout
请参阅:从存储过程中返回数据 [ ^ ]
这篇关于如何在一个CTE中使用两个select语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文