Author |
Topic |
asif372
Posting Yak Master
100 Posts |
Posted - 2013-01-10 : 04:16:23
|
My Data is like thisEID TIMEIN TIMEOUT1 9:00 10:001 12:00 14:002 10:00 16:00I want to Add this Data in Table naming NewTable my Table Columns are followingEID,TIME,TYPEi want data to be fillid in my table using Stored Procedure like thisEID TIME Type1 9:00 I1 10:00 O1 12:00 I1 14:00 O2 10:00 I2 16:00 OHow can it be possible Thanks In Advance.... |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-01-10 : 04:27:22
|
[code]SELECT EID,TIMEIN AS [Time],'I' AS TypeFROM tableUNION ALLSELECT EID,TIMEOUT,'O'FROM TableORDER BY EID,[Time][/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
asif372
Posting Yak Master
100 Posts |
Posted - 2013-01-10 : 04:29:26
|
Thanks for your Responce,I want to Insert Not Select Man... |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-01-10 : 04:32:34
|
quote: Originally posted by asif372 Thanks for your Responce,I want to Insert Not Select Man...
Is it so difficult to add a insert logic to it?INSERT into NewTable (EID, TIME, Type)SELECT EID,TIMEIN AS [Time],'I' AS TypeFROM tableUNION ALLSELECT EID,TIMEOUT,'O'FROM TableORDER BY EID,[Time] ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-01-10 : 04:35:49
|
Alternate is:INSERT ITNO NewTableSELECT EID, Times, CASE keyCol WHEN 'TIMEIN' THEN 'I' ELSE 'O' END Type FROM (SELECT * FROM @t) pUNPIVOT (Times FOR keyCol IN (TIMEIN, TIMEOUT))pvt--Chandu |
|
|
asif372
Posting Yak Master
100 Posts |
Posted - 2013-01-10 : 04:41:17
|
visakh16 i think that i was unable to convey my point to you in a better way..well i want to insert my data using logic i will give Following Parameters to Procedure@EID int,@TimeIn Datetime,@TimeOut Datetime,@Remarks varchar(50)now when inserting record to Table Logic will be implemented like if Timein then Checktime and 'I' as TypeTimeOut then Checktime and 'O' as TypeI think Loop Scenario Should be added to work on this criteria |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-01-10 : 04:47:21
|
why loop? so are you telling your values will be passed from users as parameters and not come from a table?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
asif372
Posting Yak Master
100 Posts |
Posted - 2013-01-10 : 04:50:15
|
Yes Parameter will be Passed Rather then Selecting from Table |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-01-10 : 04:51:47
|
[code]CREATE PROCEDURE myProc(@EID int,@TimeIn Datetime,@TimeOut Datetime--,@Remarks varchar(50) )ASBEGIN INSERT INTO t1 SELECT @EID,@TIMEIN AS [Time],'I' AS Type UNION ALL SELECT @EID,@TimeOut,'O'ENDGOEXEC dbo.myProc 1, '9:00', '10:00'SELECT * FROM t1[/code]--Chandu |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-01-10 : 04:59:45
|
in that case you've to call procedure each time for inserting a row of data and would be like thisCREATE PROC InsertData@EID int,@TimeIn Datetime,@TimeOut Datetime,@Remarks varchar(50)ASINSERT into NewTable (EID, TIME, Type)SELECT @EID,@TimeIn,'I'UNION ALLSELECT @EID,@TimeOut,'O'GO ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-01-10 : 05:00:49
|
one question is where are you capturing this data currently if its not in a table?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|