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



Hai I am Shiva from TN, SSE.I have an query problem. My Table : Door Field : ID,DoorID,ZoneI..

Answer / 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

More C Sharp Interview Questions

Explain the types of Polymorphism.

0 Answers   Accenture,


Is it good to use var in c#?

0 Answers  


What are the types of inheritance in c#?

0 Answers  


Give some examples of commonly used i/o classes?

0 Answers  


Is javascript harder than c#?

0 Answers  






What are the advantages of constructor?

0 Answers  


what is the need of using interface in program ex:if we have a program like this interface1() { void method1(); void method(); } class a1 : interface1 { a1 b = new b(); b.method1(); b.method2(); } so without using interface also we can achieve this then wat is the need to use the interface? plz give me the answer

1 Answers  


Explain About .NET Remoting and types of remoting

0 Answers  


Describe a Struct ?

0 Answers   Siebel,


Can we inherit private class in c#?

0 Answers  


Explain the concepts of cts and cls(common language specification).

0 Answers  


What is hashtable in c# net with example?

0 Answers  


Categories