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} ...
Related
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.
I'm trying to define the row source of a lookup field by selecting the table name from a separate lookup box.
The catalog of products comprises of about 41 Product Groups, which are then further divided into Types, some of which have over 100 types.
I have a table of Product Groups (41 groups), and I then have a separate table of Types for each Product Group (41 tables). All Type table names are exactly as they appear on the Product Group table. I want to be able to select the Product Group from a Lookup Box, and then select the Type from the corresponding table in a separate lookup box.
The images below should help give an idea of what I'm looking to do.
Set up of my first lookup box:
Set up of my second lookup:
Is this possible, and if so can anyone lend a hand ?
Thanks.
Just to summarize, you will need a single table with your TypeID, GroupID, and any other "Type" related fields.
Your Group ComboBox should have the ID field as its first column (makes the filtering much easier), So your control source should be:
SELECT [ProductGroup]![GroupID], [ProductGroup]![ProductGroup]
FROM [ProductGroup]
ORDER BY [ProductGroup];
Then in the properties for Group ComboBox on the Format tab make your column width 0";x" to hide the ID field.
The control source for the Type ComboBox should be:
SELECT [NewTypeTable]![TypeID], [NewTypeTable]![TypeName]
FROM [NewTypeTable]
WHERE [NewTypeTable]![GroupID] Like [Forms]![frmWithComboBoxName]![CboPGroup]
ORDER BY [NewTypeTable]![TypeName];
And again, if you want to hide the ID field, make the first column width 0".
You should also requery the second combobox in the afterUpdate() event of CboPGroup which will filter the second combobox based on the new selection in CboPGroup. The code (VBA) for that would be:
Forms!frmWithComboBoxName!CboType.Requery
I have the following table layout in an Excel data table (fed by a SQL query):
Name, Birthday, Children, Check In
The first three columns come from a database query, the Check In column should be a column where I can manually enter an x for example.
Now, when I refresh the data table, the entries in the last column should stay in the right row. Currently, when I refresh the table the entries stay in the very same row they were entered in (e.g. if you enter an x into row 4, refresh and row 4 becomes row 5, the x stays in row 4).
Is there a way to avoid this?
Thanks in advance!
Hopefully you have some ID that uniquely identifies each item in each row (you could use the Name column if you don't have duplicate names). Keep a copy of your old data that you have marked the "Check In" box for. Then do a basic VLOOKUP to see whether that name has check in.
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.
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.