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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Converting Filed into Rows

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2003-09-23 : 08:03:30
Diwakar writes "Hi

I want to transform field into rows.

I have table Weekly_Timesheet
structure of the table is

Emp_code
Weekend_Dt
SUN_NT
MON_NT
TUE_NT
WED_NT
THU_NT
FRI_NT
SAT_NT

I want to get list on Daliy basis for particular weekend Date or Employee;
i.e.,
Emp_Code
Date
NT

Thanx in advance"

samsekar
Constraint Violating Yak Guru

437 Posts

Posted - 2003-09-23 : 09:10:04
Are you looking something like this..

select 'emp01' empcode, getdate() as date, 1+56+89+0 as NT

Can you please explain us more on your requirement.

Sekar
~~~~
Success is not a destination that you ever reach. Success is the quality of your journey.
Go to Top of Page

TSQLMan
Posting Yak Master

160 Posts

Posted - 2003-09-23 : 16:29:57
I think you are looking for this.

Create Proc _proc_EmpTime

@EmpNo char(10) --or whatever datatype Employee is
@Wdate datetime

AS

IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME = '#EmpTime')
DROP TABLE #EmpTime

CREATE TABLE #EmpTime
(
Emp_code char(10), --Or whatever datatype
Weekend_Dt smalldatetime,
DAY_NT as decimal
)

INSERT INTO #EmpTime

SELECT Emp_Code, Weekend_Dt, SUN_NT

FROM Weekly_Timesheet

WHERE Weekend_dt = @Wdate and Emp_Code = @EmpNo

--Next

INSERT INTO #EmptTime

SELECT Emp_Code, Weekend_Dt, MON_NT

FROM Weekly_Timesheet

WHERE Weekend_dt = @Wdate and Emp_Code = @EmpNo


--Next

INSERT INTO #EmptTime

SELECT Emp_Code, Weekend_Dt, TUE_NT

FROM Weekly_Timesheet

WHERE Weekend_dt = @Wdate and Emp_Code = @EmpNo


--Next
--........... Paste the insert and change the DAY_NT field until ------you have all 7.

Select * from #EmpTime

Drop Table #EmpTime


You could use a cursor and loop through the recordset, This is just to make sure what you are looking for. Did I get it?
Go to Top of Page
   

- Advertisement -