Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 problem in writing stored procedure

Author  Topic 

jaimin
Starting Member

21 Posts

Posted - 2007-10-30 : 08:17:01
hi,
i am new to this.
in my aspx page, i am having a dropdown which has two value
Name
EmpID

if user clicks on name from drop down, user has enter the name of employee in a textbox. And if user clicks on EmpID, he has to enter the employee ID in textbox.

Based on selection the data will be displayed in grid view.

In my database, i have a table called EmpInfo, which has three fields - EmpName, EmpID and State.


can anybody help me in writing a stored procedure for this??

Thanks
Jaimin

nr
SQLTeam MVY

12543 Posts

Posted - 2007-10-30 : 08:21:27
create proc s_Get_EmpInfo
@Data varchar(100) ,
@Type varchar(20) -- 'ID', 'Name'
as
select EmpName, EmpID, State
from EmpInfo
where (@Data = EmpID and @Type = 'ID')
or (@Data = EmpName and @Type = 'Name')
go


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

arorarahul.0688
Posting Yak Master

125 Posts

Posted - 2007-11-02 : 04:51:40

make two stored procedures one for name, one for id
this just because of consideration of performance issues

make a if else statement at c# coding if id selected then
procedure for id will called or if name selected then procedure for name is called

create procedure fetch_data
@name varchar(12)
as
begin
select "columnname to be fetch" from tablename
where name="col_name column that contains the name list"
end

call execute fetch_data in name part of if else statement

Rahul Arora
MCA 07 Batch
NCCE Israna, Panipat
HRY, INDIA

######################
IMPOSSIBLE = I+M+POSSIBLE
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-11-02 : 05:15:14
You could just have one text box called, say, FIND and let the user type ID, name, Phone number, etc. in there ... and then have an SProc that uses a "broad" query to find matches - ranking those with exact match higher than partial match and, presumably, and Employee ID match higher than a ZipCode ... depends on the type of user I suppose.

Kristen
Go to Top of Page
   

- Advertisement -