wafw1971 Posted February 7, 2013 Share Posted February 7, 2013 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 More sharing options...
justsomeguy Posted February 7, 2013 Share Posted February 7, 2013 There are several examples here, if you're using SQL Server: http://msdn.microsoft.com/en-us/library/ms174420.aspx Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now