Jump to content

Adding new columns to a table using the datepart function Sql


Recommended Posts

Morning Everyone, I have just started training on SQL and was wondering if you could help with a problem I have encountered. I have populated a column with a date via the CREATE TABLE FunctionUSE OccupancyCREATE TABLE Time(Date date not null) DECLARE @StartDate Date, @EndDate Date SET @StartDate = '01 Jan 2010'SET @EndDate= '31 March 2015'WHILE @StartDate <= @EndDate BEGININSERT INTO TimeVALUES (@StartDate)SET @StartDate = Dateadd(dd,1,@StartDate)ENDBut what I would like to do now is create 4 Extra columns called CalendarYear, CalendarMonth, FinancialYear and finally FinancialMonth, I know I should use the Datepart function but not matter how many time I have written it, it doesn't seem to work.All help is much appreciated.ThanksWayne

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...