Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to programmatically establish a fieldname
Message
De
27/03/2014 13:42:54
 
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
How to programmatically establish a fieldname
Versions des environnements
SQL Server:
SQL Server 2012
Application:
Web
Divers
Thread ID:
01597493
Message ID:
01597493
Vues:
61
Hi all -

I have this SQL which seems to work OK. Suggestions are welcome.
		SQL = "select f.FundType, "
		SQL += "(select sum(amount) from TIP_ApprovedFunding where FundType=f.FundType and YEAR=@TipYear) as Year1, "
		SQL += "(select sum(amount) from TIP_ApprovedFunding where FundType=f.FundType and YEAR=@TipYear + 1) as Year2, "
		SQL += "(select sum(amount) from TIP_ApprovedFunding where FundType=f.FundType and YEAR=@TipYear + 2) as Year3, "
		SQL += "(select sum(amount) from TIP_ApprovedFunding where FundType=f.FundType and YEAR=@TipYear + 3) as Year4, "
		SQL += "(select sum(amount) from TIP_ApprovedFunding where FundType=f.FundType and YEAR=@TipYear + 4) as Year5, "
		SQL += "SUM(amount) as Total "
		SQL += "From TIP_ApprovedFunding f "
		SQL += "inner join TIP_Projects p on f.TipID = p.TipID "
		SQL += "where p.ApprovedStatus = 'Active' and f.YEAR between @TipYear and @TipYear+4 "
		SQL += "group by f.FundType"
I would like to replace the column names Year1, Year2, etc with the actual year as established by the @TipYear parameter, but I've not been able to find a way to do this. Can someone help?
Thanks
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform