October 7, 2011 at 12:40 pm
Hello All,
Have a need where I pass in the start month and end month as an ints to a stored proc. The data has hard coded fields for months. For example, column names are 'month1', 'month2', 'month3' ... up to 'month12'.
Now 'month1' is suppose to be October, 'month2' is suppose to be November, etc.
when i pass in the start month and end month values of ints to the proc, i am suppose to select start month to end month columns in the select statement. What is the best way to do this?
Thanks for your time.
October 7, 2011 at 1:02 pm
To get a tested answer, please post your tale definition, some sample data and required results. To do this in a readily consumable manner pleas click on the first link in my signature lock and read the article, which by the way includes T-SQL statements to allow you to provide the information easily
October 7, 2011 at 1:03 pm
Query the data vertically, returning months as rows, and have the presentation layer pivot it. Excel, SSRS, CrystalReports, et al, can pivot rows into columns efficiently and well.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
October 8, 2011 at 1:51 pm
ramadesai108 (10/7/2011)
Hello All,Have a need where I pass in the start month and end month as an ints to a stored proc. The data has hard coded fields for months. For example, column names are 'month1', 'month2', 'month3' ... up to 'month12'.
Now 'month1' is suppose to be October, 'month2' is suppose to be November, etc.
when i pass in the start month and end month values of ints to the proc, i am suppose to select start month to end month columns in the select statement. [font="Arial Black"]What is the best way to do this?[/font]
Thanks for your time.
For the way you have it laid out, Dynamic SQL to build the correct SQL Statement.
--Jeff Moden
Change is inevitable... Change for the better is not.
October 11, 2011 at 6:22 am
I agree with GSquared.
I had a similar problems lining up the appropriate lengths and pressures of a mathematical problem along with offset calender months.
Using the transpose tool on the origin data made it easier to work with.
Can you feedback on how you got on with this?
I've got another project coming up for an SQL database to sort and verify the amp output of a batch counter against a current input for an ampere hour meter It's not even something i fully understand...
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply