SSRS - Parameter based on reference table - sql

I have multiple datasets with the WHERE clause = #customernumber.
I have a customer number data set that contains a field with a unique id and a field that contains multiple ids.
I.e.
Customer Number | Old Customer Numbers
123 123
123 34324
123 4363
123 124214
345 345
345 436346
345 234532
678 678
I want to be able to search in the parameter box for the old customer number but use the customer number in querying my datasets.
My datasets only contain the customer number, not the old customer numbers.

While creating the parameter you can select the value and the label of the dropdown list.
In the Available Values tab select Get values from a query, for dataset just choose the dataset that query the table with new and old codes. In Value field select the new code and in the Label field select the old code.
UPDATE:
Create a parameter called OldCode. Set the data type to text or integer based on old customer code number. Don't use default or available values for this parameter.
Create a dataset that use the #OldCode parameter to return the customer number. Use something like this:
select
Customer_Number
from CustomerTable
where Old_Customer_Number = #OldCode
Create a parameter called CustomerNumber. Set Hidden property and select the data type based on the Customer_Number column. In Default Values tab select the dataset created previously and the Customer_Number column as Value field.
After that you can use #CustomerNumber in all your datasets. When user input a old code the #CustomerNumber will be populated with the related Customer_Number value.
Let me know if this helps.

Related

What is the best SQL query to populate an existing column on table A with a similar column from table B?

Let's say I have an existing table A with a column called contact_name and a ID column id as the primary key.
All the rows in A have the name value as "NULL" right now.
Another table B has different columns, but one of which is contact_name, and another is ref_id.
Each ref_id in B corresponds to a value of id in A, and there may be multiple rows in B that share the same value for ref_id (meaning they all correspond to a single entry in A).
Let me set up an example:
Table A
id | contact_name
1 | [NULL]
2 | [NULL]
Table B
ref_id | contact_name
1 | "John"
2 | "Helen"
2 | "Alex"
Note there are theoretically other values in each table but for the sake of brevity I'm just showing the values I'm interested in using.
I want to populate contact_name in table A with the first entry of the corresponding contact_name in B, where B.(first)ref_id = A.id, without adding any rows or editing the rest of the rows in either table. That is, I want A in my example to now be:
id | contact_name
1 | "John"
2 | "Helen"
Again, note how the first contact_name value, "Helen", in B is selected, not any other subsequent one, like "Alex".
The MERGE function is made for this. Give it a try:
MERGE INTO TABLEA a USING (
SELECT b.REF_ID, b.CONTACT_NAME
FROM TABLEB) b
ON (a.ID = b.REF_ID)
WHEN MATCHED THEN
UPDATE SET
a.CONTACT_NAME = b.CONTACT_NAME
WHERE a.CONTACT_NAME IS null;
You could try using Five, a low-code development environment that lets you manage your MySQL database, and build a web application on top of it.
Whenever You can add a new column in a Table, Five will give you a prompt where you can use a query to populate that particular column.
Here are the steps:
Import your existing MySQL database into Five
Add a new column to your database.
Five will prompt you to fill in values for the new column. Five gives you four options:
A. you can leave the new column empty,
B. assigned a Default value,
C. Copy Values to an existing field
D. Write a custom query.
Refer to This Screenshot to get an idea how things look inside Five
Hope this helps!
Disclaimer: I work for Five

Access 2014 SQL update table value from unbound form

I am trying to update a value in a table from an unbound form. The user needs to choose the product name, enter a sales value and then the value updates the correct record in the table. At present I have:
UPDATE tblStock
SET tblStock.Sold = [Forms]![frmItemsSold]![Text3]
WHERE ((([tblStock]![ProductName]=[Forms]![frmItemsSold]![Combo1])));
The form is frmItemsSold and Combo1 on the form has the product name. Text3 on the form contains the sold value which should update the correct record in the Sold field in tblStock. At present my code doesn't work. Any ideas?

REPORT -Visual Studio 2012

I am new to report.Dataset patient is a dropdownlist.Here I want to add a NULL field so thaT if i select Null it must retrieve some values from database.How can i create a NULL field in The dropdownbox of a report as below.But it is not working for me
http://msprojectnow.com/blog/reports-in-ssrs-with-multi-value-parameters-and-null-values
Assuming you are talking about a report parameter and that you intend to use Reporting Services Server to host the report. I usually find the approach below works to give provide an empty value to pick. So you add a dataset for the patient dropdown and use the query below as the data source for example.
select 0 as PatientID, ''as Patient
Union
Select PatientID, Patient
Order By Patient
Then you select Query as you source for your Patient parameter pick this data source and choose patientID as the value and Patient as the display value. If you do the same for default value but just pick Patient id, the bank value will show as your initial selection when you run the report.

Access - Check if a value exists in another table after insert

I have a table with the field "Name" among the others. When I insert a new value in that field, I need a check to see if it exists in another table (same field, "Name"), and if it doesn't, I need that it creates a new row in this table with the value inserted
Example:
First Table Second Table
Name Cost Name Cost
John 1000€ John 1200€
John 200€ James 2000€
James 2000€
If I try to insert, for example, "Mark" in the first table, since it isn't in the second table, it adds a new row in the second, so the result is
Second Table
Name Cost
John 1200€
James 2000€
Mark 0€
The check is on the field "name"
Here is the actual database, but it is in italian. The Form "Commesse" has the button "aggiungi cliente" where I write a new name and then save it with "Salva cliente". I need that the other three tables and relative forms to have updated the "Nome_Cliente" field.
This is easy to do with an After Insert data macro on the first table:
For more information on data macros, see:
Create a data macro

Get values based on newly inserted value using SQL

I want to make filtration on a column after selecting a specific value of another column in the same table, I tried to use #... special character followed by the column's name to get the address of this value.
My SQL statement is like the following :
SELECT ATTRIBUTE FROM TABLE WHERE FIELD = '#FIELDNAME';
If I used a specific value instead of #FIELDNAME, it will work properly but it will be static but I need it to be dynamic based on the selected value.
Create another table which will have the list of values that are in the FIELDNAME and give each record a unique id ,then retrieve the value depending on what you have selected by the name of the new table's field preceded by '#...'
I don't know if that what are you looking for, please let me know.
If no triggers are allowed, do you have any date/time column in the table? Is it possible to have that extra column anyway to see the time of a newly inserted row?
You may have to check the lastest row entered, save its field value into a variable. Then do the select based on the variable value.
Based on the vague last row id you could try the following (it's not pretty). But again, if you have date/time that's more accurate.
select attribute from table
where field = (select field from table
where rowid =(select max(rowid) from table))
;
upate
Do you have the priviledge to set up your insert command as below:
insert into table (id, col1, col2,...) values (1,'something', 'something',...)
returning id into variable; -- you may either save field or id depending on your table
Then you may use this variable to select the records you want.