Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Every One,

I have following code please help me out

@RecordCount is a output Parameter in Store Procedure

SQL
;WITH CTE AS
(
   SELECT *
   FROM TableName
   
)
    Select @RecordCount = Count(*) from CTE


    Select * from 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..
Posted
Comments
[no name] 7-Oct-14 2:57am    
Your question is not clear

1 solution

You don't need CTE.

SQL
DECLARE @rcount INT = 0
SELECT @rcount = COUNT(*)
FROM TableName

--it would return the count of records
SELECT @rcount AS RecordCout


Please, see: Return Data from Stored Procedure[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900