Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hai

i have to select statements

select * from emp;
select count(*) from emp:

how can i put this two statements in a single storedprocedure
Posted

Hi Prasad

Assuming you are using sql server, here is the thing

Create proc test
as
begin
SQL
select * from emp
select count(*) from emp

end

Hope this helps....
 
Share this answer
 
Comments
Prince Antony G 18-Nov-11 0:47am    
my 5+
 
Share this answer
 
Comments
Prince Antony G 18-Nov-11 0:47am    
my 5+
You can include count statement in select,

select *,COUNT(*) OVER () AS RecordCount from emp
 
Share this answer
 
Comments
Prince Antony G 18-Nov-11 0:47am    
my 5+
CREATE PROCEDURE sp_EmployeeInfo
AS
BEGIN
select * from emp
select count(*) from emp
END

OR

if you want to get the no. of rows in the same table, so can write a single query instead of two statements as-

CREATE PROCEDURE sp_EmployeeInfo
AS
BEGIN
select count(*) as NoofRecords,* from emp
END
 
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