Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Convert single record with a range into multiple records
Message
De
07/01/2010 16:51:00
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
01442682
Message ID:
01442690
Vues:
28
Thank you so much for all your ideas. You are generating them faster than I can test them. But then I am slow. :)

Thanks again

>Another solution using recursive cte - took me some time because I got bitten by integer math - had to ask my friend Denis Gobo to help.
>
>;with cte as
>(
>
>
>select cName, nStartYear, nEndYear from @T
> union all
> select cName, 
> convert(Numeric(4,0),(convert(int,nStartYear) + 1))   as nStartYear, 
> nEndYear from cte where nStartYear < nEndYear
>)
>select cName, nStartYear as nYear from cte order by cName, nYear
>
>
>>Hi All,
>>I need help construct SQL Statement in T-SQL, which will convert single record with a range into multiple records. (MS SQL Server 2005)
>>
>>The source table has structure like:
>>
>>cName nChar(50)
>>nStartYear numeric(4,0)
>>nEndYear Numeric(4,0)
>>
>>cName nStartYear nEndYear
>>Name1 2000 2003
>>Name2 2010 2012
>>Name3 2010 2010
>>
>>The resulting set should look like
>>cName nYear
>>Name1 2000
>>Name1 2001
>>Name1 2002
>>Name1 2003
>>Name2 2010
>>Name2 2011
>>Name2 2012
>>Name3 2010
>>
>>Thank you in advance
>>
>>Yelena
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform