Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Fezi
Starting Member
3 Posts |
Posted - 2014-03-28 : 06:06:38
|
Hi, I have a Column in my data that gives a financial period value in the YYYYMM format. i.e. an asset was re-valued in a particular period for example 201301. I need to find out the number(count) of periods(months) between another given period for example current period (201403) and the period provided in the table i.e. 201301.Is this possible in the SQL Database?Thanks,FeziFezi |
|
MuralikrishnaVeera
Posting Yak Master
129 Posts |
Posted - 2014-03-28 : 06:36:41
|
DECLARE @TEMP TABLE ([StartYear] DATE,[EndYear] DATE)INSERT INTO @TEMP VALUES('20130327','20140227') SELECT (CAST(DATEDIFF(MONTH,[StartYear],[EndYear]) AS VARCHAR)+' '+'Months') AS Count FROM @TEMP---------------Murali KrishnaYou live only once ..If you do it right once is enough....... |
|
|
Fezi
Starting Member
3 Posts |
Posted - 2014-03-28 : 07:39:49
|
Hi Murali,That would work except that my period values are YYYYMM so I will need the query to look something like the following but then it wouldn't work because that is not the correct date format.DECLARE @TEMP TABLE ([StartYear] DATE,[EndYear] DATE)INSERT INTO @TEMP VALUES('201203','201402') SELECT (CAST(DATEDIFF(MONTH,[StartYear],[EndYear]) AS VARCHAR)) AS Count FROM @TEMP Any ideas?Thanks,Fezi |
|
|
|
|
|