Background: MS SQL Server 2008
Experience Level (1-10 with 10 being expert): 5
I know how to take a field that is defined in SQL server as datetime and extract the date only value.
I get the following results:
v_date
8/30/2017
8/30/2017
8/31/2017
8/31/2017
What I need to do is take v_date and compare to today's date (which is 8/31/2017). I have tried this
and get this as a result:
Messages
Msg 207, Level 16, State 1, Line 3
Invalid column name 'v_date'.
What am I doing wrong?
Thank you in advance.
Experience Level (1-10 with 10 being expert): 5
I know how to take a field that is defined in SQL server as datetime and extract the date only value.
Code:
SELECT Convert(varchar(2),DATEPART(MONTH, regi_datetimein)) + '/' + Convert(varchar(2),DATEPART(DAY, regi_datetimein)) + '/' + Convert(varchar(4),DATEPART(year, regi_datetimein)) as v_date from [DB04_Visitors].[dbo].[T040200_REGISTRATION]
v_date
8/30/2017
8/30/2017
8/31/2017
8/31/2017
What I need to do is take v_date and compare to today's date (which is 8/31/2017). I have tried this
Code:
SELECT Convert(varchar(2),DATEPART(MONTH, regi_datetimein)) + '/' + Convert(varchar(2),DATEPART(DAY, regi_datetimein)) + '/' + Convert(varchar(4),DATEPART(year, regi_datetimein)) as v_date from [DB04_Visitors].[dbo].[T040200_REGISTRATION] where v_date='8/31/2017'
Messages
Msg 207, Level 16, State 1, Line 3
Invalid column name 'v_date'.
What am I doing wrong?
Thank you in advance.
Comment