954,560 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

stored procedure to select value and return

Hi there,
How can I write a stored procedure to select a value from a table and return that value??
I have a table Employee, when I send the email as a parameter to the stored procedure, I should get the employee number (it should return the employee number)
I am trying to execute the stored procedure in C# code.
I wrote a code but not sure about this and it is wrong how can I fix it

CREATE PROCEDURE dbo.getEmpID
declare @empid int
AS
BEGIN
/* SET NOCOUNT ON */
Select @empid From Employee Where Email=@empid

END

appriciate if some one could guide me


thankxxxxxxx

judithSampathwa
Posting Pro in Training
453 posts since May 2010
Reputation Points: 8
Solved Threads: 0
 

You don't want to select @empid, you want to select the column in your table that contains the ID. @empid should be set to the email address of the Employee.

Momerath
Nearly a Senior Poster
3,386 posts since Aug 2010
Reputation Points: 1,232
Solved Threads: 558
 
You don't want to select @empid, you want to select the column in your table that contains the ID. @empid should be set to the email address of the Employee.

no i want the employee number to bereturned, when the email addreee is provided as the input parameter

thanks

judithSampathwa
Posting Pro in Training
453 posts since May 2010
Reputation Points: 8
Solved Threads: 0
 

what momerath was saying is that the way you have it set up right now you will be returning your parameter, not the employee number from your employee table.
it should be something like...

Select empNumber From Employee Where Email=@empid

Oreo1982
Newbie Poster
16 posts since Jun 2008
Reputation Points: 10
Solved Threads: 0
 

what momerath was saying is that the way you have it set up right now you will be returning your parameter, not the employee number from your employee table. it should be something like...

Select empNumber From Employee Where Email=@empid

ohh yeah it should b @email,
if so is the query correct???

thanxxxxx

judithSampathwa
Posting Pro in Training
453 posts since May 2010
Reputation Points: 8
Solved Threads: 0
 

select empnumber from employee where email = @email... there should not be an @ in the select.

Oreo1982
Newbie Poster
16 posts since Jun 2008
Reputation Points: 10
Solved Threads: 0
 
select empnumber from employee where email = @email... there should not be an @ in the select.

ok,
so how do you get the empID from the c# code when executing the stored procedure????

thanxxxxxxxxxx

judithSampathwa
Posting Pro in Training
453 posts since May 2010
Reputation Points: 8
Solved Threads: 0
 

I have not used C#, sorry, i can't help you there. i use asp.

Oreo1982
Newbie Poster
16 posts since Jun 2008
Reputation Points: 10
Solved Threads: 0
 
I have not used C#, sorry, i can't help you there. i use asp.

that is fnie how do u can in asp????

judithSampathwa
Posting Pro in Training
453 posts since May 2010
Reputation Points: 8
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: