T-SQL Query help to Compare the even_time value with current year and month

Hi,

I have the following code block

CREATE TABLE #tbl_1 (event_time DATETIME2, SID INT ,NAME VARCHAR(20) ) INSERT INTO #tbl_1 VALUES ('2015-08-27 13:47:24.123','150','abc') INSERT INTO #tbl_1 VALUES ('2015-09-27 13:47:24.123','149','acb') INSERT INTO #tbl_1 VALUES ('2015-10-27 13:47:24.123','148','cba') CREATE TABLE #tbl_2 (event_time DATETIME2, SID INT ,NAME VARCHAR(20) ) INSERT INTO #tbl_2 SELECT * FROM #tbl_1 where ?

SELECT * FROM #tbl_2

My requirement is to insert values into #tbl2 that are in current month which are event_time values

'2015-08-27'

thanks

Bhanu





  • Edited by bhanu_nz 4 hours 21 minutes ago
August 26th, 2015 10:52pm

?= left(convert(varchar(6),getdate(),112),6)= left(convert(varchar(6),event_time,112),6)

CREATE TABLE #tbl_1  (event_time DATETIME2, SID INT ,NAME VARCHAR(20) )
INSERT INTO #tbl_1 VALUES ('2015-08-27 13:47:24.123','150','abc')
INSERT INTO #tbl_1 VALUES ('2015-09-27 13:47:24.123','149','acb')
INSERT INTO #tbl_1 VALUES ('2015-10-27 13:47:24.123','148','cba')

CREATE TABLE #tbl_2 (event_time DATETIME2, SID INT ,NAME VARCHAR(20) )
INSERT INTO  #tbl_2
SELECT * FROM #tbl_1 where left(convert(varchar(6),getdate(),112),6)= left(convert(varchar(6),event_time,112),6)

SELECT * FROM #tbl_2



  • Edited by pIdrA 4 hours 10 minutes ago
Free Windows Admin Tool Kit Click here and download it now
August 26th, 2015 11:02pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics