Hai
I am Shiva from TN, SSE.I have an query problem.
My Table : Door Field :
ID,DoorID,ZoneID,Date,Time,Status.
Problem was : Status.We got two values, one is 00
(OUTTIME) , Another is 01(INTIME)

Like this
Status
---------
00
01
00
01
00
01
00
01

How to Set as Status 00 and 01 , of separate column ,
Status as Intime,Status as Outtime

Like this
-----------

InTime OutTime
---------- -----------

01 00
01 00
01 00
01 00
01 00
01 00

Regards
KS kumar

Answer Posted / shahid

Make your Record like below:

With CTE AS(RowId, Status)
(
SELECT ROW_NUMBER() AS RowId, Status
FROM MyTable
)
INSERT INTO #Temp
Now In your New Table CTE. Record Will be like that:
RowId Status
1 00
2 01
3 00
4 00

Now Apply the While loop with Condition
DECLARE @RowID INT = 1
DECLARE @Count INT
SELECT @COUNT = COUNT(RowId) FROM #Temp
WHILE @COUNT > 0
BEGIN
DECLARE @Status INT
SELECT @Status = Status
FROM # Temp
WHERE RowId = @RowId
IF(@Status = '01')
BEGIN
INSERT INTO MyNewTable(InTime) VALUES(@Status)
BEGIN
ELSE
BEGIN
INSERT INTO MyNewTable(OutTime) VALUES(@Status)
END
SET @RowId = @RowId + 1
SET @Count = @Count - 1
END
DROP TABLE #Temp

This query will seperate the value..
You can change it as your condition required.

Regards,
Shahid Ansari

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between ienumerable and enumerator?

448


What is a hashset c#?

476


What are the 4 pillars of any object oriented programming language?

451


What is escape sequence in c#?

597


What is append in c#?

480






what are some characteristics of an array?

525


Define thread?

580


What is the difference between // comments, /* */ comments and /// comments?

499


Explain the accessibility modifier protected internal?

462


Can you describe iuknown interface in short?

617


What is a console in c#?

486


What will a loop recorder show?

549


Can we store different data types in arraylist in c#?

469


what is collections in .net? why we use?

1688


I wish to create a windows application to perform a similar function as that of the "Search" which is provided to look for related files and folders in the System.. What steps must i follow??

1533