Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
CREATE FUNCTION getCountID( @EmpID INT) 
RETURNS int
AS BEGIN
DECLARE @COUNT INT
SELECT COUNT(*) INTO @COUNT FROM Emp_table
RETURN @COUNT
END

i am getting error while creating this functio. where i am doing wrong.please help
Posted
Updated 8-Apr-14 2:57am
v2

You are making mistake.
correct it
SQL
SELECT @COUNT=COUNT(*) FROM emp_table
 
Share this answer
 
SQL
SELECT COUNT(*) INTO @COUNT FROM join1

SELECT ... INTO ... FROM... is to fill tables with data. To set a single variable to the result of a select use this form:
SQL
SELECT @COUNT = COUNT(*) FROM join1

Read more here: http://technet.microsoft.com/en-us/library/ms187330.aspx[^]
 
Share this answer
 
Comments
DipAnikap 8-Apr-14 9:01am    
i got it thank..u
Your select state was not ok here it should be

SQL
SELECT @COUNT = COUNT(*) FROM Emp_table


Full Function:


SQL
CREATE FUNCTION getCountID
( 
	@EmpID INT
) 
RETURNS int
AS 
BEGIN
	DECLARE @COUNT INT
	SELECT @COUNT = COUNT(*) FROM Emp_table
	RETURN @COUNT
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