I want a combo box that can do a query search from multiple fields and return the product ID. The function of this combo box is that there are three fields product ID, Name and bar code. Now the user searches from any one of those fields and the option should come from those three fields, after the user selects an option it should store it as the product Id. I tried working on this problem but the only far I could go was that i could only search from one field for example by only its name. So is this function possible to code and if it is then how to code it?
If you want user to enter ProductID, Name, or bar code into same combobox and return the ProductID, then make the combobox RowSource a UNION query of the three fields:
SELECT ProductID, ProductID AS Data FROM tablename
UNION SELECT ProductID, ProductName FROM tablename
UNION SELECT ProductID, BarCode FROM tablename;
Set other combobox properties:
ControlSource: field to save ProductID into
BoundColumn:1
ColumnCount: 2
ColumnWidths: 0";2"
Strongly advise not to use spaces nor punctuation/special characters in naming convention. Also, Name is a reserved word and should not use reserved words as names for anything.
Related
I need to run a query in a MS Access Database providing some parameters from a form. Imagine the next example:
I have a form which contains:
CheckBox1 and Text1
CheckBox2 and Text2
Button (to run query)
Now imagine a query with two fields: ID, NAME.
I want to filter ID by Text1 only when CheckBox1 is enabled. If not, I want the query not to filter ID in any way (as if the 'query' input was empty).
In the same way, I want to filter NAME by Text2 only when CheckBox2 is enabled. If not, I want the query not to filter NAME in any way (just like ID before).
I've tried so many things for a couple of days and have sniffed tons of internet pages and still don't come up with a solution.
You can use a SQL query such as the following:
select * from YourTable t
where
([Forms]![YourForm]![CheckBox1] = False or t.ID = [Forms]![YourForm]![Text1]) and
([Forms]![YourForm]![CheckBox2] = False or t.NAME = [Forms]![YourForm]![Text2])
(Change YourTable to the name of your table and YourForm to the name of your form; t is merely an alias so that you only have to change the table name in one place in the code).
I have SSRS report that showing Marketing Features. we have in the MF a field called "Test", the values are "PSI 1" or PSI 2" and also the field can be empty.
I added a dataset for the Test parameter with this query:
SELECT DISTINCT Corp_Test
FROM [Tfs_Warehouse].[dbo].[CurrentWorkItemView]
WHERE ProjectNodeGUID = #ProjectGuid
AND System_WorkItemType = 'Marketing Feature'
UNION
SELECT 'Null'
ORDER BY Corp_Test
Now in the report, the values are PSI 1 PSI 2 and Null:
In the Main Query I filtered the results according to the parameter like this:
where COALESCE(Corp_Test, 'Null') IN (#TestParam)
The report works fine, and if I selected all values I get also Marketing Features with empty Test field.
My question is:
Instead of Null on the dropdown, I want it to be written No PSI and actually in the main query it will be Null. is it possible?
In your parameter properties, on the Available Values screen you will see an option for the Value and the Label. This allows you to show one thing to the end user (eg: user friendly description) whilst passing another (eg: key value) to the report.
In your dataset for the test parameter add a column to hold the Label of the value you want to pass through to the query. This can be the same as your Value if you so wish, but gives you the flexibility you require on the Null entry:
SELECT DISTINCT Corp_Test as Value
,Corp_Test as Label
FROM [Tfs_Warehouse].[dbo].[CurrentWorkItemView]
WHERE ProjectNodeGUID = #ProjectGuid
AND System_WorkItemType = 'Marketing Feature'
UNION ALL -- As you have DISTINCT above, UNION ALL will work faster and give the same results as UNION (which removes duplicates)
SELECT 'Null' as Value
,'No PSI' as Label
ORDER BY Corp_Test
Once you have done this, change your parameter to use the Value field as the parameter value and the Label field as the label shown to the user.
SELECT
ISNULL(Corp_Test,'No PSI') AS Corp_Test
FROM
(SELECT DISTINCT Corp_Test
FROM [Tfs_Warehouse].[dbo].[CurrentWorkItemView]
WHERE ProjectNodeGUID = #ProjectGuid
AND System_WorkItemType = 'Marketing Feature'
UNION
SELECT 'Null'
) AS Corp
ORDER BY ISNULL(Corp_Test,'No PSI')
Remember to implement the change in your where clause main query. By main query, I mean the query that is feeding your report
The simple and easiest way is what #sgeddes answered in his comment.
I just repleced the where COALESCE(Corp_Test, 'Null') IN (#TestParam) with where COALESCE(Corp_Test, 'No PSI') IN (#TestParam), and in the dataset I replaced the SELECT 'Null' with SELECT 'No PSI'.
I'm handling this problem here in company: We have different customers, that need different fields in the same table, but we do not want to have a table with 300 columns, which is inneficient, hard to use and so on. Example:
table_products have this fields: product_id, product_name, product_cost.
then, the first client 'X' needs the field product_registerid.
the client 'Y' needs the field product_zipareaid.
That happens by different causes. Example: they are from different states, that have different rules.
At this moment we came up with this solution, which i don't like:
product_id, product_name, product_cost, product_personal. In this product_personal we have saved values like '{product_registerid:001;product_zipareaid:001-000131}'.
I came up with a theoretic solution: extend the table, and the sql will know when i do a query in the extended table, and shou me the column with the main table's column. Something like:
table_products with columns product_id, product_name, product_cost.
table_products_x with column product_registerid.
table_products_y with column product_zipareaid.
And the querys would return:
1.
select * from table_products where product_registerid = 001:
product_id, product_name, product_cost, product_registerid
1, iphone, 599, 001.
2.
select * from table_products where product_zipareaid = 000-000110:
product_id, product_name, product_cost, product_zipareaid
1, iphone, 599, 000-000110.
So, im accepting different suggestions for solving our problem.
Thank you in advance!
One approach would be to add a single Extended Properties table, that would look something like this:
Product_id (FK)
Client_id
PropertyName
PropertyValue
And so it would be populated with values like:
Product_id Client_id PropertyName PropertyValue
1 x product_registerid 001
1 y product_zipareaid 000-000110
Then you just join table_products to Extended_properties on Product_Id and put the Client_id(s) you want in the WHERE clause.
Note that you'll probably end up wanting to use a PIVOT query to get multiple extended properties for each client.
I'm trying to create a combo box that has the only the field names from
a table in it and not the items in that field. So for example I have a
table with 40 fields in it like Account#, Name, address, phone # etc...
I want to click on the combo box and have the option to choose a field
and not the data within the specific field. So when I click the drop
down it will show all the fields in the table (Account#, Name, address,
phone..) I've tried a few different idea's from people but cant get
it to work. I'm using Access 2002 if that helps.
An Access combobox has a option for Row Source Type of 'field list'.
Just set the Row Source Type to 'Field List' and select the table from the Row Source dropdown.
you can use the sp_columns stored procedure for sql server to get a list of column names for a given table
i have a table named locations of which i want to select and get values in such a way that it should select only distinct values from a column but select all other values .
table name: locations
column names 1: country values : America, India, India, India
column names 2: state/Province : Newyork, Punjab, Karnataka, kerala
when i select i should get India only once and all the three states listed under India . is ther any way..??? sombody please help
You could do this:
SELECT country, GROUP_CONCAT(state SEPARATOR ', ')
FROM locations
GROUP BY country
But this sort of thing is often best done in the presentation layer.
You want it displayed in that order, not selected?
In this case you have to add a condition inside of your loop to check a country and print ot out only if it was changed.