Community
Showing results for 
Search instead for 
Do you mean 
Reply

Excel OLE DB - SQL Query using WHERE

Accepted Solution Solved
New Member
Posts: 5
Country: United_Kingdom
Accepted Solution

Excel OLE DB - SQL Query using WHERE

[ Edited ]

Hi all,

 

Hopefully a quick one, got my data connections up and running, and trying to make my query a bit more elegant so I only actually "pull down" the data I need. So I have:

 

SELECT Field1, Field2, "Stupidly named field", Field3 FROM CONTACT;

 

This works fine. As soon as I add a WHERE, then it all falls over, e.g.

 

SELECT Field1, Field2, "Stupidly named field", Field3 FROM CONTACT WHERE CONTACT.Field1 = "foo"; 

 

This just throws up an error message. Any ideas? I'm stumped as its a "proper" SQL query as far as I can see, so wondering if its a restriction or a quirk in ACT?

 

Thanks


Accepted Solutions
Solution
Accepted by topic author ed_fry
‎02-24-2016 08:33 AM
Nickel Contributor
Posts: 175
Country: USA

Re: Excel OLE DB - SQL Query using WHERE

I'm not sure on restrictions from Excel, but I do know what SQL Server likes. If you have weird field names, it's best to enclose them in brackets such as [There Are Spaces In This Field Name]. As for literal strings (your "foo"), you want to use single quotes, not double. This would make your Where clause into this...
WHERE CONTACT.Field1 = 'foo'

If those tweaks don't help, could you please post the error that you're getting?

View solution in original post


All Replies
New Member
Posts: 5
Country: United_Kingdom

Re: Excel OLE DB - SQL Query using WHERE

No-one got any ideas?
Administrator
Posts: 4,024
Country: United_Kingdom

Re: Excel OLE DB - SQL Query using WHERE

I've moved your thread to the Developers forum in order for your question to find a more suitable audience.
Solution
Accepted by topic author ed_fry
‎02-24-2016 08:33 AM
Nickel Contributor
Posts: 175
Country: USA

Re: Excel OLE DB - SQL Query using WHERE

I'm not sure on restrictions from Excel, but I do know what SQL Server likes. If you have weird field names, it's best to enclose them in brackets such as [There Are Spaces In This Field Name]. As for literal strings (your "foo"), you want to use single quotes, not double. This would make your Where clause into this...
WHERE CONTACT.Field1 = 'foo'

If those tweaks don't help, could you please post the error that you're getting?
New Member
Posts: 5
Country: United_Kingdom

Re: Excel OLE DB - SQL Query using WHERE

Perfect, been doing too much VBA work and not enough SQL recently, thanks! Smiley Happy