Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Results from Query as Headers

Status
Not open for further replies.

SqlCoderGirl

Programmer
Aug 26, 2008
1
US
I'm providing a user with a report on accounts with activity by month for the previous 6 months. By pulling the month out of the activity date, I want to use it in the column headers.

For example, if I kick off the query on 8/4, the results should be similar to

ID February March April May June July
xxx 12345 254 4521 4521 541 4587

The headers change dynamically, depending on when the query is run. I'm trying to use datename(month, activitydate) to pull in the month name, but can't figure out how to get it into the header.

Any suggestions???
 
In order to have dynamic headers you'll nee to do the query using Dynamic SQL.

Denny
MCSA (2003) / MCDBA (SQL 2000)
MCTS (SQL 2005 / Microsoft Windows SharePoint Services 3.0: Configuration / Microsoft Office SharePoint Server 2007: Configuration)
MCITP Database Administrator (SQL 2005) / Database Developer (SQL 2005)

My Blog
 
How about returning column results and then pivoting the table?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top