How to call a sql server stored procedure

Hi, I have a stored procedure parameters are emp_no, avgsal.number

i have data in a table.my request is take emp_no from table and pass parameter to procedure .

For this one i want create a procedure and temp table.

ALTER procedure [dbo].[SalaryRetrivial]
as
begin
declare @TSQL nvarchar(200)

set @TSQL='select distinct emp_no from dbo.employee'
Create Table #Temp
(
avgsal int
,emp_no nvarchar(10)
)
insert into #Temp
(
avgsal,
emp_no
)
exec dbo.DebtScoreProcedure @TSQL,0,' ',

select d.emp_no,d.emp_name,t.avgsal from dbo.employee d
inner join  #Temp t on d.emp_no=t.emp_no
end
GO

i got zero result when execte a procedure can you help on this please




July 28th, 2013 2:17am

what does this SP do?

exec dbo.DebtScoreProcedure @TSQL,0,' ',

Free Windows Admin Tool Kit Click here and download it now
July 28th, 2013 2:49am

stored procedure has two 3 arameters

emp_no--- input

avgsal---out

number---out

when i was in debugging the procedure gave result

July 28th, 2013 3:02am

I do not think the syntax is correct for calling stored procedure having 3 parameter,

exec dbo.DebtScoreProcedure @TSQL,0,' ',

Remove the last comma character from the command and try once.

Secondly, i do not think we need OUT parameter. Share the code for dbo.DebtScoreProcedure, that will help us.

Free Windows Admin Tool Kit Click here and download it now
July 28th, 2013 3:07am

I removed comma but i got zero result
July 28th, 2013 3:14am

Refer the below example, hope it clarifies.

-------------------------
CREATE PROCEDURE TESTING(@QRY NVARCHAR(MAX))
AS
BEGIN
	EXEC(@QRY)
END
--------------------------
DECLARE @TEMP TABLE(DT DATETIME)
INSERT INTO @TEMP
EXEC TESTING 'SELECT GETDATE()'
SELECT * FROM @TEMP

------------------------- Regards, RSingh


Free Windows Admin Tool Kit Click here and download it now
July 28th, 2013 3:37am

Thank you for your replay. but my table has more than one value
July 28th, 2013 3:50am

ALTER procedure [dbo].[SalaryRetrivial]
as
begin
	declare @TSQL nvarchar(200)
	set @TSQL='select distinct emp_no from dbo.employee'
	Create Table #Temp(avgsal int,emp_no nvarchar(10))
	insert into #Temp(avgsal,emp_no) exec DebtScoreProcedure @TSQL
	select d.emp_no,d.emp_name,t.avgsal from dbo.employee d
	inner join  #Temp t on d.emp_no=t.emp_no
end
-------------------------------------------
create procedure DebtScoreProcedure(@TSQL nvarchar(max))
as
begin
	declare @strs nvarchar(max)
	set @strs = 'SELECT avg(salary) as avgsal,emp_no FROM TABLENAME WHERE emp_no IN (' + @tSQL + ')	GROUP BY  emp_no'
	exec(@strs)
end

Free Windows Admin Tool Kit Click here and download it now
July 28th, 2013 4:06am

Thank you for give replay. actually i don't want average salary.instead of avg(salary) any posiible to mentioned my own stored procedure

July 28th, 2013 4:59am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics