Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have table emp in which there is emptype which includes temp, perm and seasonal.
I am in need of find the information regarding all emptype or temp, perm and seasonal in dropdown.
how can I do that? I am using C# in this project with sql server 2014
And this is web application
Posted
Updated 22-Dec-14 8:05am
v2
Comments
Kornfeld Eliyahu Peter 22-Dec-14 13:25pm    
http://mattgemmell.com/what-have-you-tried/

You should have a translation table for referential integrity, you would then query that table, not the employee table.

EmpType
ID Name
1  Permanent
2  Temporary
3  Seasonal


Employee
ID EmpType Name ...
1  1       Bob
2  1       Joe
3  2       Bill
 
Share this answer
 
Comments
Maciej Los 22-Dec-14 15:21pm    
Sounds reasonable, but i'm afraid OP might do not understand it.
PIEBALDconsult 22-Dec-14 16:01pm    
Well, I didn't understand the question, so we're even.
Before you start, please apply changes suggested in solution1 by PIEBALDconsult[^].

You can achieve that by extracting emptype to new table:
SQL
--create new table
CREATE TABLE EmpTypes
(
    EmpTypeID INT IDENTITY(1,1)
    TypeDescription NVARCHAR(50)
)

--insert empTypes
INSERT INTO EmpTypes(TypeDescription)
SELECT DISTINCT EmpType
FROM Emp

--update emp table
ALTER TABLE Emp ADD COLUMN EmpTypeID INT REFERENCES EmpTypes(EmpTypeID)

UPDATE t1 SET t1.EmpTypeID = t2.EmpTypeID
FROM Emp AS t1 INNER JOIN EmpTypes AS t2 ON t1.EmpType = t2.TypeDescription 

ALTER TABLE Emp DROP COLUMN EmpType

Note: above query could contain errors, i couldn't test it.

Finally, create procedure:
SQL
CREATE PROCEDURE GetObviousData
    @startdate DATETIME,
    @enddate DATETIME,
    @emptype INT
AS
BEGIN
    --SELECT statement
    SELECT t1.<Field_List2>, t2.<Field_List>
    FROM Emp AS t1 INNER JOIN EmpTypes AS t2 ON t1.EmpTypeID = t2.EmpTypeID
    WHERE t1.EmpTypeId = @emptype AND t1.HireDate BETWEEN @startdate AND @enddate
END


MSDN documentation:
ALTER TABLE[^]
UPDATE[^]
CREATE PROCEDURE[^]
CREATE TABLE[^]
 
Share this answer
 
v2
Comments
patelv61 22-Dec-14 20:15pm    
since I have store proc created I need to use this store proc in dropdown or combobox in Visual studio 2013 and dropdown consist of all of the Typedescription and Perm, Temp and Seasonal any idea
I have store proc which has 3 parameter in which there is startdate enddate and emptype which this three variable or parameter utilize populate datagrid or piechart from .NETCHART and piechart has click event which result in datagriid

Thank you very much
 
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