Problem using wildcards(*) in Excel vba sql statement - sql

Ive been trying to get this sql statement to work properly through excel vba.
SELECT * FROM Documents WHERE (((Documents.doc_Comment) Like *" & [SStr] & "*));
This works 100% in access, what i want it to do is allow for a search based on part of the doc_comment field.
example Search for BOB
ID | Doc_comments
1 | Bob is a person
2 | Person name is Bob
3 | Seven is a number
The search would return only the first and second.
As i said above the access query is easy to get working but as soon as i add in excel it all goes to hell. Ive tried using stored queries in access to no avail, even tried writing a temptable but as soon as i call the query from excel and pass the parameter the query fails and gives no results.
Ive tried searching around and cant find anything that helps.
Thanks alot
Edit note-made example data more readable

If you are using ADO in Excel, it is case sensitive and the wild card is % not *.
To be a little clearer, the wild card for ADO is always %.

The only wildcard that worked for me was %.
Edit - my experience applies to Excel with ADODB driver only. In my project I had the same problem - "*" symbol used as wildcard gave me errors. Once I used "%" it worked. I did not spend time investigating...

Related

Do I have problem with some hidden characters in MS Access?

I use data from MS Excel further in MS Access where I try to create several Queries. My Table contains the following numbers:
Table:
"111_1"
"222_2"
"123_3"
So, if I've built those query, I always receive not correct results:
Query:
like "###_#" | 0 Results
not like "###_#" | 3 Results
Why do I experience this kind of behavior? How can I avoid it? It seems like my inputs contains some hidden characters
Thank you
The octothorpe designates a digit, so try with:
"###?#"
or:
"###_#"

Weird Access Query Problem - Running Saved Access Query Can't Find Fields. Is this a Buffer problem?

Version 1 of the problem:
I create a simple (or complex) SQL query that works and save it, and then come back to it another day and try to run it. I get a message that it cannot find a field that is clearly in the table. If I copy the exact same query into a blank SQL window it works fine.
Version 2 of the problem:
Another version of this type of problem is when I write a query, run it a bunch of times, and then modify it in the same window, it sometimes (=quite often but not always) can't find a field that is clearly in the table. Again, copying the same query into a new window works just fine.
An example:
SELECT *
FROM table1
WHERE code1='xxx' and code2= 'yyy'
ORDER BY sortfield
I get the window saying 'Enter Parameter value for field Query1.sortfield' .
sortfield is in the table and copying this query to a new window works fine.
And to be clear, the query worked fine when first written.
Seems like Access is not properly clearing the buffer somehow.
I have Access 2010 and this happens very frequently, like maybe but not quite always, and seems to be getting worse. I have always had version 2 of the problem to some extent but version 1 is relatively new.
Does anyone have an idea of how to fix this?
Help is much appreciated!

SQL Server function returns different results in two different query panes

Got me flummoxed!: I have a function that I call...
SELECT UNIT
FROM POWER_ASSETS.[dbo].[returnbaseload] ('03-12-2015','EUR')
WHERE C_TIC = 'LSE:SOE'
The function "returnbaseload" queries values from a view and does some calcs with the values. Simple. It returns 29 rows.
If I open it up in a new SQL query tab, copy n paste... it returns 533 rows.
If I copy and paste from new tab back to old tab.... 29 rows.
Any ideas? Got me beat.
P.S have also tried putting
Use POWER_ASSETS
GO
just in case there was a duplicate table accidentally created somewhere in the master...
I am worried because I am calling the function eventually from a vb program and am getting the wrong amount of rows from the sql query in vb. That's what got me investigating... the right amount of rows was from the new tab, 533 rows.
There's no way a deterministic select fetches different result sets when using the same parameters. Period.
As comments indicates you must being overloking or missing something.
1 - Be sure both panes are using the same.
[SERVER/INSTANCE].[DATABASE].[SCHEMMA].[TABLE]
it's by far the most common scenario.
It also is valid for function/SP calls. Be sure you are calling the same object and not a different version of it.
2 - Be sure both are using the same user/privileges.
Maybe you are using different connection parameters
.
3 - Be sure there's no implicit convertion messing with your query.
You are using some sort of varchar to date convertion here. Be sure you got the same settings (collation, copy from a unicode to a UTF-8 archive, etc.) in both tabs. Also you can try to query the table using some sort of GETDATE() function instead of dealing with that varchar literal.
4 - Be sure your data is not changing while you query it.
Stop the server and put it in single user. Maybe your data is just being updated.
5 - Be sure there are not any random function in the query.
Sometimes we got funny BL and someone unintented put some rand logic in it.
6 - Be sure you are not just drunk or tired.
Once I and a friend where working for like +20hrs no stop. He got angry with a buggy "dot" in the screen. Turned ou it was a actual bug (a fly) and also tried to get rid of it with the mouse pointer.
Calm down and call a friend to get a look on it.

SELECT query using LIKE property in Microsoft Access returns no results when it should

I'm sure I'm making some kind of rookie error here, but I have no idea what the problem is. I am trying to run a simple query on one table in a microsoft access database using the LIKE property to find records that have a certain text string in a particular field. More specifically, the table, called Catreqs, has a few fields, bib_num, MARC_336, MARC_337, and MARC_338. The MARC_336 field has a text string in it and I want a query that selects all the records for which that text string includes the characters "txt".
Here's my query:
SELECT [Catreqs].record_num, [Catreqs].MARC_336
FROM [Catreqs]
WHERE [Catreqs].MARC_336 Like '%txt%';
I should note that I created this query in MS Access design view and this is the query that was generated when I switched to SQL view. I am a little familiar with SQL and even less familiar with Access so this is actually my preferred way of dealing with it.
I've also tried using Like '*txt*' but that didn't return any results either. For reference, here is the entire text string these characters are in:
text txt rdacontent
Any suggestions thoughts on why this fails and how I can fix it?
Thanks!
In Access, for a string you must use the * character.
Check if [Catreqs] has rows where MARC_336 contains "txt".
This is the official documentation of Access:
https://support.office.com/en-us/article/Like-Operator-b2f7ef03-9085-4ffb-9829-eef18358e931?ui=it-IT&rs=en-001&ad=IT&omkt=en-001

Find and replace from spreadsheet into spreadsheet...(Hard to sum up, sorry)

I know the title isn't informative at all, but I had no idea how to sum up my question. I have 2 spreadsheets, one of them 400+ words paired with a number for each word and the other one has has the text that I will be using. So the first spreadsheet looks like this:
Column A Column B
afds 0
dshs 1
dhid 2
. .
. .
. .
dgsrs 456
And the second spreadsheet looks something like this:
Column A Column B
dhid afds
dshs dgsrs
etc. etc.
I would like to get the second spreadsheet to display the numbers that are assigned to the strings in the first spreadsheet. So I would eventually like to end up with a spreadsheet that looks like this:
Column A Column B
2 (used to be dhid) 0 (used to be afds)
1 (used to be dshs) 456 (used to be dgsrs
(The comments in brackets is just to explain, I don't want them in the final spreadsheet)
So I started doing find&replace (find a string in the second spreadsheet and replace it with the value that is assigned to it in the first spreadsheet), but I know that there must be a script for this. I am not extremely familiar with any language, but so far I have been able to run simple scripts in languages I hadn't seen before, so if you know any solution to this, please let me know, I don't care what programming language it is in, I can google a way to run it as long as it runs on mac os x (c compiler installed).
Thanks in advance!
While you could write a script to do this, the use of a translation table is common enough to be supported in many spreadsheet formula languages. In Excel-flavoured languages -- I'll use OpenOffice on the Mac, although this works with Numbers as well -- you can use the function VLOOKUP. Its calling syntax in OO looks like
VLOOKUP( valueToSearchFor ; tableToSearchIn ; columnIdentifier ; isTableSorted)
Probably easier to show it, so:
On the left hand side I put your translation table. In the centre were the cells to be translated. And on the right I wrote the formula VLOOKUP(D3; $A3:$B6; 2; 0), which translates into "look for the value of cell D3 in the translation table in the fixed region from A3-B6, use the second column as the values, and the table isn't sorted so don't try to take shortcuts while searching". Then I simply copied that cell from F3 to the F3:G4 region, to match the shape of the central data columns.
BTW, I can never remember which programs are happy with semicolons and which ones need commas, so you may need to change that.. Seaching for VLOOKUP and whatever program you use should give you all the tutorials you need. I think modern Excel even automates the process.