I want to get all the use tables.
SELECT name FROM MSYSOBJECTS WHERE TYPE=1 AND NAME NOT LIKE 'MSys*'
That is ok directly execution in access.
But When it's in MFC code
m_pRecordset->Open("SELECT name FROM MSYSOBJECTS WHERE TYPE=1 AND NAME NOT LIKE 'MSys*'", m_pConnection.GetInterfacePtr(), adOpenDynamic, adLockOptimistic, adCmdText);
There are tables
MSysObjects MSysACEs MSysQueries MSysRelationships
included.
Why?
/*****************************************************/
I've already got the answer
SELECT name FROM MSYSOBJECTS WHERE TYPE=1 AND NAME NOT LIKE 'MSys%'
I've already got the answer
SELECT name FROM MSYSOBJECTS WHERE TYPE=1 AND NAME NOT LIKE 'MSys%'
Related
i want some correction here. i want to select all people with name fred in database
Here's my query:
SELECT * FROM tdble WHERE CONCAT(name) LIKE CONCAT('%', REPLACE('fred', '')'%')
What you are asking can be simply achieved by either using the "=" operator of the wildcard operator "like" statement.
If you wish to find all records that have an exact match to the name 'Fred' then you should model your query as so:
Select * From tdble Where Name = 'fred'
However, if you want to get all results where the names have 'fred' included in it somewhere use the wildcard operator.
Select * From tdble Where Name like '%fred%'
Also you can further model your query to know where exactly in which form you want 'fred' to appear. Example if you want 'Fred' to be as the last characters of your name string, for instance you wish to get names which ends with fred then model your query like this:
Select * From tdble Where Name like '%fred'
(you will get results like 'alfred', provided there is an alfred in your table)
However if you wish to get all names that begin with fred, model the query like this:
Select * From tdble Where Name like 'fred%'
(you will get results like 'fredinane', provided there is a fredinane in your table)
Cheers
If you want to fetch record with name 'fred', you can simply do Select * from TableName Where Name = 'fred'.
If you want to fetch records which their names' string contain 'fred', you have to use select * from TableName where Name like '%fred%'
I would like to write a query in Access 2013 to mark the first time a word appears as "Yes" and all subsequent times as "No". I have included a sample below. The "Distinct" column is what I would like my query to generate.
Thank you
Word Distinct
First Yes
Second Yes
First No
Third Yes
Here is one approach:
SELECT *, IIf(DMin("ID","Table1","[Word]='" & [Word] & "'")=[ID],"Yes","No") AS FirstWord
FROM Table1;
Another:
SELECT *, IIf([ID] = (SELECT TOP 1 ID FROM Table1 AS Dupe WHERE Dupe.Word = Table1.Word ORDER BY Dupe.Word, Dupe.ID), "Yes", "No") AS FirstWord FROM Table1;
DISTINCT is a reserved word so I am avoiding using it as a field name.
I am using Microsoft Access 2013
I need to make a query so that the program can grab the last name of the ACTOR'S NAME when the ACTOR'S name has their full name for example Kelly Garman, and Weird Al Yankovic. Yankovic has 3 values and Garman has 2 values. Any help?
There are over 10,000 records with tons of different names, so I need to have it so the user will be asked to input the last name and once they do, the database will query by the last name.
Its also a query where the user inputs something in when asked.
Columns in the database are in the SELECT statement
SELECT [RECORD #], [ACTOR'S NAME], [PRODUCTION NAME]
FROM Actors AS A
WHERE [A.ACTOR'S NAME] = [What's the last name?]
The Database file is here. https://drive.google.com/open?id=0B19CRcQGkXoVTTZpaldDWnFuS28
You can use REVERSE along with SUBSTRING as below to get the last name.
REVERSE( SUBSTRING( REVERSE([ACTOR'S NAME]), 1, INSTR(' ', REVERSE([ACTOR'S NAME])) - 1))
To find the last name you need to get the word after the last space. You can't do this directly in MS Access. Instead, you can find the position of the last space with InstrRev(Name, ' '). Then use Right to get everything to the right of that, but that takes a position from the end of the string. To get that, subtract what you got from InstrRev from the length of the name.
SELECT Right(Name, Len(Name) - InstrRev(Name, ' ')) as 'Last Name'
FROM Actors
WHERE Right(Name, Len(Name) - InstrRev(Name, ' ')) = 'Yankovic';
Unfortunately I do not have a copy of MS Access to test this.
You can use a pattern match in the WHERE clause.
PARAMETERS [What's the last name?] Text ( 255 );
SELECT A.[Record #], A.[ACTOR'S NAME]
FROM Actors AS A
WHERE A.[ACTOR'S NAME] ALike '% ' & [What's the last name?];
I'm trying to use a query to narrow the table down to only the rows in which the field [full name] contains the value in the field [first name].
For instance, if a row has "Blake Johnson" in [full name] and "John" in [first name] - this row will be included.
But if [full name] has "Garry Sways" and [first name] has "Swan" - this row will NOT be included.
I tried to use:
Like "*[first name]*"
In the criteria for [full name].
But it didn't work quite well.
Is there a "Contains" funciton for this case?
Thanks in advance.
Just do this
SELECT * From yourTable WHERE instr(fullname, firstname) > 0
I am not sure what kind of query language you are using but you can use regular expressions to make a more granular version of "like"
For example, in MySql you can do:
SELECT * FROM 'foo' WHERE 'bar' REGEXP "^\$"
or in your case:
SELECT * FROM table WHERE fullname REGEXP (".*" + firstname + ".*");
I'm very new to access. I have a data in my column that looks similar to this:
JONES/KEN
SMITH/TAMMY
MILLER FRED
PICARD.JOHN
Am I able to grab the letters before the first non-alphanumeric?
So my result would be:
JONES
SMITH
MILER
PICARD
How about a derived table:
SELECT Left([Surname],InStr([Surname],[NonAlpha])-1) AS LeftName,
MainTable.Surname
FROM MainTable,
(SELECT " " As NonAlpha From Table1
UNION
SELECT "." As NonAlpha From Table1
UNION
SELECT "," As NonAlpha From Table1
UNION
SELECT "/" As NonAlpha From Table1) AS n
WHERE (((MainTable.Surname) Like "*" & [nonalpha] & "*"));
Table1 is a scratch table, it does contain records but the query will only
return the four assigned rows (,./ )
Maintable is the table with a field Surname, which is the field to be split.
Unfortunately, I don't know of a "Word" function that's available in some languages. I would do it with brute force checking using Instr and then Mid to extract the code. The construct would be very convoluted to get every kind of character.
I've used the iif function and nested it - this the basic format here:
iif (instr (fieldname,"{the character}") > 0,
mid(fieldname,1, instr(fieldname,"{the character}")-1,
fieldname{or go further into ifs})
Using your sample data with Client Name as the field and 3 conditions - space, / and period. IT does work, but it's ugly - you will have to scroll pretty far to the right to get everything:
ShortName: IIf(InStr(1,[client_name]," ")>0,
mid(client_name,1,InStr(1,[client_name]," ")-1),
IIf(InStr(1,[client_name],"/")>0,
mid(client_name,1,InStr(1,[client_name],"/")-1),
IIf(InStr(1,[client_name],".")>0,
mid(client_name,1,InStr(1,client_name],".")-1),
Client_Name)))
Put this in a query based on your table.