Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to programmatically establish a fieldname
Message
From
27/03/2014 13:42:54
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
How to programmatically establish a fieldname
Environment versions
SQL Server:
SQL Server 2012
Application:
Web
Miscellaneous
Thread ID:
01597493
Message ID:
01597493
Views:
60
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
Next
Reply
Map
View

Click here to load this message in the networking platform