Author |
Topic |
kshahzad
Starting Member
45 Posts |
Posted - 2013-07-11 : 14:19:04
|
I have this query running perfectly fine and the result set looks like thisNumberRows Time_stamp ----------- -----------------------------940 2013-07-11 18:00:00.357Now i want to insert these two columns values in a new table.i cant figure out how can i do this.DECLARE @dCurrentTime DATETIMEDECLARE @dCurrentTimeMinus5 DATETIME--Declare @counttotal intSET @dCurrentTime = GETDATE()SET @dCurrentTimeMinus5 = DATEADD(minute, -5, @dCurrentTime)--insert into UsersLoggedIn (NumberRows,@dCurrentTime);SELECT Count(*) As NumberRows, @dCurrentTime as Time_stampFROM ( SELECT lID FROM SessionState_Variables WHERE dLastAccessed BETWEEN @dCurrentTimeMinus5 AND @dCurrentTime GROUP BY lID) As SessionsTableRegards |
|
MuMu88
Aged Yak Warrior
549 Posts |
Posted - 2013-07-11 : 14:39:28
|
quote: Originally posted by kshahzad I have this query running perfectly fine and the result set looks like thisNumberRows Time_stamp ----------- -----------------------------940 2013-07-11 18:00:00.357Now i want to insert these two columns values in a new table.i cant figure out how can i do this.DECLARE @dCurrentTime DATETIMEDECLARE @dCurrentTimeMinus5 DATETIME--Declare @counttotal intSET @dCurrentTime = GETDATE()SET @dCurrentTimeMinus5 = DATEADD(minute, -5, @dCurrentTime)insert into UsersLoggedIn (NumberRows, Time_stamp) -- insert the exact column names from the new table hereSELECT Count(*) As NumberRows, @dCurrentTime as Time_stampFROM ( SELECT lID FROM SessionState_Variables WHERE dLastAccessed BETWEEN @dCurrentTimeMinus5 AND @dCurrentTime GROUP BY lID) As SessionsTableRegards
|
|
|
kshahzad
Starting Member
45 Posts |
Posted - 2013-07-11 : 14:47:08
|
No this is a syntax error |
|
|
MuMu88
Aged Yak Warrior
549 Posts |
Posted - 2013-07-11 : 14:55:28
|
what is the error? |
|
|
kshahzad
Starting Member
45 Posts |
Posted - 2013-07-11 : 15:02:30
|
Msg 207, Level 16, State 1, Line 13Invalid column name 'NumberRows'.Msg 207, Level 16, State 1, Line 13Invalid column name 'Time_stamp'. |
|
|
MuMu88
Aged Yak Warrior
549 Posts |
Posted - 2013-07-11 : 15:21:24
|
Can you show the definition of the table named "UsersLoggedIn"quote: Originally posted by kshahzad Msg 207, Level 16, State 1, Line 13Invalid column name 'NumberRows'.Msg 207, Level 16, State 1, Line 13Invalid column name 'Time_stamp'.
|
|
|
kshahzad
Starting Member
45 Posts |
Posted - 2013-07-11 : 15:23:03
|
Create TABLE UsersLoggedIn (TotalUsers int,TimeRecorded datetime); |
|
|
MuMu88
Aged Yak Warrior
549 Posts |
Posted - 2013-07-11 : 15:25:37
|
Try this:quote: Originally posted by MuMu88
quote: Originally posted by kshahzad I have this query running perfectly fine and the result set looks like thisNumberRows Time_stamp ----------- -----------------------------940 2013-07-11 18:00:00.357Now i want to insert these two columns values in a new table.i cant figure out how can i do this.DECLARE @dCurrentTime DATETIMEDECLARE @dCurrentTimeMinus5 DATETIME--Declare @counttotal intSET @dCurrentTime = GETDATE()SET @dCurrentTimeMinus5 = DATEADD(minute, -5, @dCurrentTime)insert into UsersLoggedIn (TotalUsers, TimeRecorded ) -- insert the exact column names from the new table hereSELECT Count(*) As TotalUsers, @dCurrentTime as TimeRecordedFROM ( SELECT lID FROM SessionState_Variables WHERE dLastAccessed BETWEEN @dCurrentTimeMinus5 AND @dCurrentTime GROUP BY lID) As SessionsTableRegards
|
|
|
kshahzad
Starting Member
45 Posts |
Posted - 2013-07-11 : 15:53:23
|
Awesome..Thanks |
|
|
|