How do I map dynamically created columns in SSRS 2008? - dynamic

I wrote a stored procedure, whose results include 4 columns whose names will change over time.
They correspond to Week numbers. So one column will be '1', another will be '2' and so on.
They will continue to change when the report runs, ie, '49','50','51','52'. In Report Builder you have to map column name to column name, but the column name will change, they are not static.
Any idea how I can do this?

SSRS does not support dynamic column names. I would recode your stored procedure to return a Week column with values 1, 2 etc.

Related

One row per column with column name

background
I am trying to create an SSRS report which will run select * on a table passed in as a parameter and display all the data from that table. As I understand it, I can't use a table for this. I want to use a pivot table to achieve this.
select * from #table will return something like this (from the adventureworks DB)
I want to display the date in this format:
Question
How do I achieve this? I looked at using PIVOT/UNPIVOT, but all the examples I've seen use static column names and aggregates.
I won't know the column names at design time (or run time), I'm assuming I will need column headers like 'table name', 'value1', 'value2' etc?
Limitations
I won't have access to create stored procedures. Ideally, the report should be able to be run entirely from SSRS without having to create new tables etc.
Performance is not a concern.
Edit
Editing to add some clarity. The column names in the example above are only an example. The #table parameter could be any table, column names won't be know at design time. The column names could be col1, col2, or name, address... etc.
You can do this with a normal tablix, with a column group on BusinessEntityID
Create a normal tablix.
Remove the row group (group only)
Insert a new parent column group, grouped by BusinessEntityID
Delete the top row (row only)
Add each of the row titles in, as per your suggested output
Add each of the values in the second column

how can I link rows of a SQL table for some columns but not others?

I have a table of values in excel that I want to put into sql as a lookup table. the table looks like this:
the sql table looks like this:
having this in SQL, I now want to never use the excel file ever again.
I also need the ability to change the parameters, but some of them in the excel file were linked by merging the cells and thereby shared the same value, if it changed for one it changed for all.
for example: when I change Parameter B for Product 1, I need it to change it for Products 2, 3, 4, and 5 because they share the same cell in the excel table. And if I change parameter A for Product 2, It only changes for product 2 and 3. I am looking for a SQL Query solution. I have the ability to change the table structure as well.
Here goes my example query:
Update [Table] Set [Parameter_A] = '{new_parameter_tag}'
Where [product] = '{selected_product_tag}'
except I want to have the Where include all the rows that share the same cell from the excel table.
I want to be able to update the SQL table for multiple products at a time based on if they share the same cell for that parameter in the excel file.
here is my initial guess at an answer:
Select [{Parameter}],[Product],[Extra_column]
From [Table]
Where [Product] = '{selected_product}'
this returns one row and [Extra_column] that contains a grouping number shared by others in the same cell grouping. this then gets stored as {Extra_column}. then:
Update [Table] Set [{Parameter}] = '{new_parameter_value}'
Where [product] = '{selected_product}' Or [Extra_column] = '{Extra_Column}'
this requires two queries and also means that i need twice as many columns as i had before. I am looking for something a little more elegant.
This is SQL Server 2012 and the {} indicate a value that I am passing in form a script.
I ended up doing something similar to what I had above, the user enters the group they want to edit (it's pretty easy to pick out which one you want when viewing the table) as:
Update [table]
Set [{Parameter}]={NewValue}
Where [Extra_Column] = '{Extra_Column}'
I had to add three columns for the grouping indexes but over 43 parameters that doesn't add much to my table size. I did not take into account the fact that if I change a single parameter for a single product that would remove it from the "group" essentially for just that parameter, and later I would overwrite the changed value if I do a group change for that parameter. I could add in a check to only change values that match within that group but either way the user will have to be smart about what they do. luckily, they can see the table before they change it.

How to Use dynamic column name in vb.net (with visual studio 2005)

Hi I am creating an attendance system where i want that for a particular id given by user, attendance of that id get saved in the MS access sheet.
What i am wanting is that column name should be i date format pre created by me nad as user enters the id the program retrieves date from system and based on that date (taking it to be dynamic column name) writes an p on them.
I am using SQL query to update i.e using update statement
now i am unable to find correct syntax for using dynamic column name..
So can any one help me??
If I understand what you are saying... I would change the schema you are envisioning to have a table with "ID" and Date Columns. This prevents you from having a fixed and huge number number of date columns.
You insert a new row in this table for an ID and date combination.
I am also assuming you want a report that pivots the data where you have ID in Column position 0 and dates as column headers? Since you are using Access you can create a Cross Tab Query
(pivot) to accomplish this.

Get specific cell in Crystal Report

I have a Crystal Report linked to table Customer in SQL Server database. My report generator will execute SELECT SQL and pass the result table into the report as data source.
In the report, I have a field and I want this field to display the cell data at the specific row index and column index of the table (maybe I know the column name). For example, my field should display cell at row 3, column 2 of the data source.
How can I do this using Crystal Report. The latest version now is 2011.
First off, in order for the row number to have any meaning, you'll need to be querying the table with an ORDER BY clause (by sorting the report). Without it, you can't make any assumptions about the "original order of records" in the DB as there really is none.
There are a few ways to get this field depending on where in the report you want to display it. If you simply want to show it in the details section, you can make use of a simple formula like this
if rownumber = 3 then {table.column}
If you'd like to display it instead in a footer, you could make use of a variable instead:
whileprintingrecords;
numbervar thedatavariable;
if recordnumber = 3 then thedatavariable := {table.column}
Throw that formula in the details section of the report and you're then free to use thedatavariable in your footers.
Now for the column: If the column index is NOT dynamic you can just see which column corresponds... for example, if the table's columns are customer_id, customer_name then column 2 will always just be the customer name. If the index number will change, like via a parameter, you could make a formula like this
select {?colIndexParameter}
case 1 : {table.customer_id}
case 2 : {table.customer_name} ...

how to find index of a row in sql server?

How can i fetch column names from a table on index basis, like I want to make a tables whose column name should be the name of last column fields of a result set of a query, but those result sets last columns value may be different at different execution time, so i want to know how can i fetch those index value of that last column to make a temp table with column name of those last columns value of a result set.
Is there any way/function in sql server to dynamically form that?
sp_helpindex:
Reports information about the indexes
on a table or view.
You can also use ROW_NUMBER as explained here