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 |
Sql_forum
Yak Posting Veteran
50 Posts |
Posted - 2013-10-15 : 06:03:34
|
Hi can some body tell me , how toconvert the below set2008200920102011201220132014into 2008-20092009-20102010-2011.......2013-2014 |
|
VeeranjaneyuluAnnapureddy
Posting Yak Master
169 Posts |
Posted - 2013-10-15 : 06:46:47
|
Declare @Te table(Id int)Insert @TeSelect 2008union all Select 2009 union all Select 2010union all Select 2011union all Select 2012union all Select 2013union all Select 2014Declare @T1 Table(Id int,Seq int)Insert @T1Select Id,row_number() Over(Order By Id) As Seq From @TeDeclare @T2 table(Id int,Seq int)Insert @T2Select Id,row_number() Over(Order By Id)+1 as Seq From @TeSelect Convert(Varchar(20),t2.Id)+' - '+ Convert(Varchar(20),t1.Id) AS 'Date' From @T1 as t1Inner Join @T2 as t2on t1.seq = t2.seq |
|
|
Sql_forum
Yak Posting Veteran
50 Posts |
Posted - 2013-10-15 : 07:15:59
|
Hi Veeru,My result set not static, it will vary from time to time |
|
|
Sql_forum
Yak Posting Veteran
50 Posts |
Posted - 2013-10-15 : 07:30:38
|
Hi Veeru,Thanks for your reply, it helped me to apply logic for my req. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-10-16 : 03:04:28
|
isnt it just a matter of this?;With CTEAS(SELECT ROW_NUMBER() OVER (ORDER BY yr) AS Seq,YrFROM table)SELECT CAST(c1.Yr AS varchar(4)) + '-' + CAST(c2.Yr AS varchar(4))FROM CTE c1JOIN CTE c2ON c2.Seq = c1.Seq + 1AND c1.Seq % 2 > 0 ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|