MYSQL Using AND and Wildcard - mysql

SQL statement is:
SELECT *
FROM cigardata
WHERE Brand LIKE '$brandS'
AND Style LIKE '$styleS'
AND Wrapper LIKE '$wrapperS'
AND UPC LIKE '$upcS';
User inputs Brand and Wrapper only and it will return nothing, normal since nothing in the other 2 fields. If I fill all 4 fields of course it works perfect. What can be used in the other 2 fields as a wild card to satisfy that all 4 fields are filled and return a result? I have tried %.%, %''%, %*%. Any suggestions......

isaace answer was the clue, the word "dynamically" led me to a solution that has been answered previously. Had to tweek it a bit with single quotes on the {$field1} to '{$field1}' and so on with the field 2 field 3 etc. Crating a Dynamic Search

Related

Use IIF and LIKE statement in critera column in queries, MS Access

I have homework from Microsoft Access for school and one of the tasks was to make a search form in query, where you type for example 1. grade, 2. grade or 1st year, etc... But the field contains the name of the classes such as IT1, IT2, E1A, E3C, etc... So I could not just make a search form with [Enter Class:] or Like [Enter Class:]&"*" in the criteria column. So I was thinking, that I can use the IIF statement but it doesn't work how I imagined. I think there is a problem with the LIKE statement. I read on forums, that the IIF statement should be used in the field column but I tried the simple examples in the criteria and it worked just fine. So my question is, how I can make a search form, where I type numerous letters with one certain number in it BUT only the number will be read and returned with the same number in classes. Example: I type to search 1. grade and the value will return classes IT1, E1A, E1B, E1C, E1D. This is the line I used in the criteria column:
Like IIf([Enter the grade:]="*1*";"*1*";IIf("*2*";"*2*";IIf("*3*";"*3*";IIf("*4*";"*4*"))))
Just to qualify, I'm beginner in access and databases overall, so there is big possibility, that I'm missing something.
Thank you for help! Cheers!
Assuming input will always start with a number and you want all values containing that number, consider:
WHERE fieldname LIKE "*" & Val([Enter grade]) & "*"
Also assumes values contain only single digit.

working with floats mysql

i am customizing a Word Press plugin named Gravity Forms, now the plugin is using a column as datatype float
now i created a totally new interface for displaying the details of an entry that is submitted, i have a set of checkboxes in the form, what Gravity Forms is doing it is adding the field_number as a floats and then the value against it
now for one set of checboxes on my form it is using the field_number as 2 now the 2 remains constants no matter how many checkboxes are selected, and after that comes some points values e.g 2.1 for a specific value and then 2.2 for a specific value and so on upto n times depending on the numbers of checkboxes in the form. please see the below image for more clarification!
Important Note! i cant change the datatype of float as something else e.g vahrchar or decimal it totally messes up the plugin
now i did struggled with getting the float values, because float are not that reliable and easy to use i have seen other blogs where people prefer double or decimal over it
my main problem was this query,
SELECT value FROM wp_rg_lead_detail WHERE lead_id=".absint( $lead['id'] )." and field_number=2.4
now running this query i did not get any result, so what i did is modified my query and passed the value as decimal!
SELECT value FROM wp_rg_lead_detail WHERE lead_id=".absint( $lead['id'] )." and CAST(field_number AS DECIMAL) = CAST(2 AS DECIMAL)
now this query worked just fine and returned the number of rows, but the problem is it is missing some data and not returning all data. like if i have 5 rows as you can see the in the image above its returns only three rows and skips the two rows! any help?
If you want compare with 2 could be you need a truncate instead of a cast eg:
SELECT value
FROM wp_rg_lead_detail
WHERE lead_id=".absint( $lead['id'] )."
and truncate(field_number,0) = 2

How to segregate a single value from a query in MS Access

My apologies but I am a bit lost in the world of Microsoft Access. So I currently have a query that returns a column of values. The output looks like this:
SMABranchCode
Code1
Code2
Code3
etc.
This query then gets moved to a form text box. To do this, I have used Control Source like so:
=IIf(IsNull(DLookUp("SMABranchCode","PWS_SM_QUERY"))," ","X")
This works "Ok"; however there are going to be probably 30+ more text boxes going horizontally next to this one all running the same query. Above them is a label with the Code. So basically when it spits out the data it looks like this (as long as there is an entry for that code):
Code 1 | Code 2 | Code 3
X | X | X
The problem is, I either need to go and create a query for each of these text boxes so that it only pulls a single entry for each Code OR I can hopefully change up my Control Source entry (=IIf(IsNull(DLookUp("SMABranchCode","PWS_SM_QUERY"))," ","X")) to include criteria so that each text box has its own Criteria, so that from the one original query, each Code (1,2,3) only displays its information.
I have tried changing DLookUp to have criteria which has looked like this:
=IIf(IsNull(DLookUp("SMABranchCode","PWS_SM_QUERY","SMABranchCode = Code1"))," ","X")
However that gives me an #Error! in the boxes I apply it too. I'm hoping maybe someone can help me figure out a solution since my brain is turning to mush over this.
Thank you
I presume SMABranchCode is a text type field. Criteria values for text fields must be delimited with apostrophes, date/time field values would use #.
"SMABranchCode = 'Code1'"

MYSQL search table, bit fields

I have a table with rows and where one field is a bit-value with 7 digits.
Suppose I have a procedure where I want to select all rows where this bit field equals '0101010', this is easily done by select * where .... and so on.
But: how do I do if I want to allow one/multiple digits of the digits to be either 1 Or 0, i.e I want to get all rows where the bitfield has an entry on the form 1001*1* where the * can be either 1 or 0. So, in this case I would like all entries where the bit field is 1001010, 1001011, 1001110 or 1001111.
select * from TABLE where bit_field in (1001010, 1001011, 1001110, 1001111) would probably work in this example, but if I want to use only the string '1001*1*' as input to the procedure, what then?
.
Any help is very appreciated.
Thanks,
Niklas
Edit: I've tried this: select * from table where field like bit'\\\0'; for getting all entries of the form **0, but that didn't work...
Edit2: It turned out it vas a bit-field, not binary... problem still remain though.
Not a direct answer to your question, per se', but an alternative approach. You mentioned that you didn't want to convert to individual columns because of legacy code. If you do want individual columns and the only thing holding you back is the legacy code, consider the following.
You could add columns for the options and use insert/update triggers to populate them OR you could create a view that splits the bits into separate columns. For new development, you can code to the new columns. Over time, as you modify legacy code you can change it to the new approach. When all the "read" legacy code has been changed, the last step is to change the "write" code to use the new columns rather than the bit column and remove the triggers.
I have a SQL Fiddle demonstrating this here. Note that I only included an insert trigger for brevity.

SSRS: How to select two or more values from a long filtered multiple selection list with different search strings

Let's consider a multiple selection parameter on a report: Employee
This parameter has a lot of possible values. Initially nothing is shown on the list and there is a textfield search parameter associated, that updates the Employee selection list with top n matches for the searched string.
If the entered search query is John Doe we can imagine that now the selection list shows:
John Doe
...
Xavier John Doesson
Now I can select as many items as I want from this filtered list, but if I want to select both John Doe and Alicia Keys happens the following:
First when I enter the search string "John Doe" the selection list gets populated accordingly
I select John Doe - OK
I enter search string "Alicia Keys", the selection list gets populated also
Selection of John Doe is gone - I want to be able to select both Alicia and John at the same time, but I don't want to go through a thousands of names long selection list
Update:
Forgot to mention that we have an OLAP cube in the background with dimension 'Employee'. This dimension is used as the source of the parameter and the param dataset uses MDX to fetch the values, therefore the SQL solution cannot be applied here.
The current solution creates an custom set with MDX Filter and Head functions and then this set is used in the ROWS-part of the MDX query.
Here is how the set created:
SET setEmployees AS {
HEAD(
FILTER( [Employees].[Employees].ALLMEMBERS,
INSTR([Employees].[Employees].CURRENTMEMBER.Name,#EmployeeSearch,1 >= 1 )
)
,100)
}
Basically the problem with this solution is that how do you add multiple search strings to the instr function
Is there a common solution to this kind of situation? Am I approaching the problem from wrong direction?
What you could do is make the search parameter more flexible, so you can handle input such as:
John OR Jane
If "OR" queries are more common than "AND" queries you could support it with queries such as:
John Jane
Note that this may throw people off, because the search features they're used to (such as Google search) typically tend interpret multiple words in the "AND" sense.
Anyhow, the tricky bit of course is the SQL behind the Employee data set. This should use the search parameter in a more flexible way. You haven't specified how that's currently working, but I imagine you may be using something like:
WHERE Employee.FullName LIKE '%' + #SearchParameter + '%'
You would need to extend that to support "OR" queries. There's a whole range of solutions for that, from quick 'n dirty handmade SQL (e.g. string split combined with WHERE...IN) to full-text querying. Choose a solution that's best for your situation.
If you have a fixed number of search terms than you can do something like the following.
FILTER( [Employees].[Employees].ALLMEMBERS,
INSTR([Employees].[Employees].CURRENTMEMBER.Name,#EmployeeSearch1,1 >= 1) OR
INSTR([Employees].[Employees].CURRENTMEMBER.Name,#EmployeeSearch2,1 >= 1)
)
Even if you can do that, I do not recommend it. You don't have the luxury to index Analysis Services like you do SQL. A better possible approach would be to query your data warehouse for the employees and return the appropriate keys, and then filter by those keys in your MDX statement.