Jump to content
Jambands.ca

Access question for any nerds out there


Groove Fetish

Recommended Posts

hi all...I tend not to post too often but I'm having troubles learning access and want to see if anyone can help me out.

I am trying to get a query to return some data and I can seem to get it to do what I want. I have a last name field and I want the datasbe to return to me any records that have certain names in them. But it is not just an equals to statement it should be a equals to or equals to or equals to....know what I mean??

so example. I have a record that says macdermid and a record that says baptiste and a record that says bosch. I want the baptiste records and macdermid records but not the bosch records. how does that statement look like.

this might be a really rudimentary question but I'm trying to teach myself access and its an uphill battle so far.

Thanks in advance for any help.

Link to comment
Share on other sites

so example. I have a record that says macdermid and a record that says baptiste and a record that says bosch. I want the baptiste records and macdermid records but not the bosch records. how does that statement look like.

I'm not sure if you're looking for something specific or generic but this would work:

select * from tablename where lastname in ('baptiste ', 'macdermid')

OR

select * from tablename where lastname = 'baptiste' or lastname = 'macdermid'

Link to comment
Share on other sites

First, take a closer look at my use of the "IN" keyword in my example.

As for this...

WHERE (((['C].[Award Date])<="2007") AND ((['C].[End Date])>="2007"));(['C] . [PI-lastname] = 'baptiste' or [PI-lastname] = 'macdermid')

I see a few things wrong here...

1. quotes used as delimiters should be single

i.e. '2007' and NOT "2007"

2. I'm not sure why you have a single quotation mark in this part: ['C].[Award Date]

3. Style note: although Access lets you, I'd avoid putting spaces in my field names; you'll avoid potential pitfalls

4. Remove that semi-colon and replace it with AND

Try those fixes and report back.

Link to comment
Share on other sites

so statement looks like this now:

WHERE (((['C].[Award Date])<='2007') AND ((['C].[End Date])>='2007')) AND (['C][PI-lastname] = 'baptiste' or [PI-lastname] = 'macdermid')

but its still saying syntax error.

I do not know how to remove the spaces from the field names?? just go into design view and delete them?

Link to comment
Share on other sites

so what happened when I switched to that was that it asked me for start dates parameters and end date parameters and last name parameters. but I thought those parameters were already in the string so shoudln't it have know that I wanted all dates >2007 and all dates ,2007 and macdermid and baptiste??? when I put in the parameters it actually retruned all the records in the database. so that one doesn't seem to work.

all this help is appreciated.

Link to comment
Share on other sites

here is the whoel statement:

SELECT ['C].[Award Date], ['C].[End Date], ['C].[PI- LastName], ['C].[PI- FirstName], ['C].[Grant Agency], ['C].[Grant Title], ['C].[$ Amount]

FROM ['C]

WHERE (((['C].[Award Date])<='2007') AND ((['C].[End Date])>='2007')) AND (['C][PI-lastname] = 'baptiste' or [PI-lastname] = 'macdermid')

Link to comment
Share on other sites

SELECT [Award Date], [End Date], [PI- LastName], [PI- FirstName], [Grant Agency], [Grant Title], [$ Amount]

FROM ['C]

WHERE [Award Date] <= '2007' AND [End Date] >= '2007' AND ([PI- LastName] = 'baptiste' OR [PI- LastName] = 'macdermid')

so this query did return records but only found the macdermid ones.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...