| Author |
Topic |
|
cyberblast
Starting Member
6 Posts |
Posted - 2004-11-22 : 07:56:25
|
| Hi, im writing a complex stored procedure...I work with temporary tables and finally i do a select over all those tables. For each output-field i have to set an alias. Some fields needs a variable fieldname, based on parameters.like SELECT #STAGE3_REND.Rend_Praemie_whr AS [Prime 99-03],...99 and 03 needs to be variable.How can i do that?PS: i can't do that with a @SQLSTATEMENT VARCHAR Variable because of the complexity...Thanks Martin |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2004-11-22 : 07:58:31
|
| Why do the column names need to change? Can you explain what you're trying to accomplish (not how you want to do it, just want you're trying to get)? |
 |
|
|
cyberblast
Starting Member
6 Posts |
Posted - 2004-11-22 : 08:03:54
|
| i'm making a replacement for an old excel-solution. the new program (access front end) makes an output of the old excel-format by calling a stored procedure (backward compatibility till the new solution is done) |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2004-11-22 : 08:11:53
|
| And the column aliases become column headings in Excel? |
 |
|
|
cyberblast
Starting Member
6 Posts |
Posted - 2004-11-22 : 08:19:30
|
| exactly... |
 |
|
|
cyberblast
Starting Member
6 Posts |
Posted - 2004-11-22 : 08:23:27
|
| I can do a workaround, but it would be cool if this i asked for is possible. i just wonder, because its possible to call funtions and use variables in the where clause too... |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2004-11-22 : 08:25:59
|
| Sorry, I should have asked this before:Is the number of columns fixed, or does it vary?Is it possible to have any variety of column headings, or do they come in fixed sets? For instance, are you running say any one of 5 fixed queries, or can the user pick and choose any columns they want?I'm thinking that if the queries are fixed, you can pre-set them in the code and simply run the proper query based on the parameters passed, instead of dynamically changing the column aliases. There's really no other way to do it since dynamic SQL is not an option for you. About the only other thing I can think of is to have some Excel macro code rename the columns after the data is put on the worksheet. |
 |
|
|
cyberblast
Starting Member
6 Posts |
Posted - 2004-11-22 : 08:32:46
|
| The amount of the columns is fixed, only some columnnames should change. I can correct this while exporting to excel, it's just unfortunate to break up my reusable excel exporter ;o) |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2004-11-22 : 09:00:39
|
quote: Originally posted by cyberblast The amount of the columns is fixed, only some columnnames should change. I can correct this while exporting to excel, it's just unfortunate to break up my reusable excel exporter ;o)
perhaps add a feature to your "excel exporter" to allow for altering or dynamically defining the column names ! (assuming you wrote it)I agree 100% with Rob, don't confuse presenting nice headings on an Excel file with changing the structure of data returned in a SQL statement. Keep things simple, and always remember the label SQL Server puts on a column in no way needs to (or should) always have to be the same verbatim as what you display to the user.- Jeff |
 |
|
|
cyberblast
Starting Member
6 Posts |
Posted - 2004-11-22 : 09:32:00
|
| thanks for your answers...the main-user agreed to a column-name change, fortunately, he also want's to keep it simple for me...Martin |
 |
|
|
|