473,378 Members | 1,389 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

SQL syntax issue with ADODB Recordset on a calc Alias

Using Access 2010 with BE - MySql (ODBC Driver 3.51) No errors when I leave out the alias and its reference. This statement was first created using Access Query Builder then moved to VBA and used in a DAO Recordset (yes this program has 2 backends) this worked just fine. The alias takes several fields to make up a key that will match one of the table records that I need to separate. Output is a string 18 char long. First 4 char uses an integer field, changes it to text, measures the length (1 to 3 char) and adds leading zero's to make it 4 char long. Then it adds 12 spaces and a 2 char field.

SELECT INV_MAST.PRODUCT_CATEGORY, INV_STORE.STORE_NUMBER, INV_STORE.CKEY, String(4-Len(Format([INV_MAST].[PRODUCT_CATEGORY])),'0') & Format([INV_MAST].[PRODUCT_CATEGORY]) & ' ' & [INV_STORE].[STORE_NUMBER] AS HKEY
FROM INV_MAST INNER JOIN INV_STORE ON INV_MAST.ITEM_NUMBER = INV_STORE.ITEM_NUMBER
WHERE (((String(4-Len(Format([INV_MAST].[PRODUCT_CATEGORY])),'0') & Format([INV_MAST].[PRODUCT_CATEGORY]) & ' ' & [INV_STORE].[STORE_NUMBER])=[INV_STORE].[CKEY]));

Gives me this error runtime error -2147217900 (80040e14) [mysql][odbc 3.51 driver][mysqld-4.0.18-log]you have an error in your sql syntax
Jan 29 '15 #1

✓ answered by jforbes

It depends on what needs to be done with the data.

If you are selecting it into a RecordSet all you would need to do is to Select the parts of the HKEY then use the String(), Len(), Format() functions in VBA to build the HKEY.

If the Select statement is only a part of the complete SQL, like an insert statement, then it is best to convert the formatting to some native SQL and run it inline so that it can be done in one single operation.

Hopefully that gets you going. If you need additional help, you can post more of the code so we can see how it is being used and we can give a more concise recommendation.

4 1405
jforbes
1,107 Expert 1GB
When executing SQL with ODBC, you need to provide the native SQL. I don't think there is a String Function in MySQL. I'm guessing then that the String, Len, Format Functions are to be called while making the String, from VBA. If this is the SQL that you are sending to the Database, you'll either need to find SQL replacements for the Functions mentioned or Build your String with those functions outside of Quotes, before performing the Execute or OpenRecordset.
Jan 29 '15 #2
I was afraid of that. Any suggestions as to how best do this since I have to read the records first before I can come up with this temporary key. There are only 10 fields within the record that I need but there could be 100,000+ records. I dont think loading it into an array is the answer. I know there are plenty of ways to do this so what I am asking is how would you do this?
Jan 29 '15 #3
jforbes
1,107 Expert 1GB
It depends on what needs to be done with the data.

If you are selecting it into a RecordSet all you would need to do is to Select the parts of the HKEY then use the String(), Len(), Format() functions in VBA to build the HKEY.

If the Select statement is only a part of the complete SQL, like an insert statement, then it is best to convert the formatting to some native SQL and run it inline so that it can be done in one single operation.

Hopefully that gets you going. If you need additional help, you can post more of the code so we can see how it is being used and we can give a more concise recommendation.
Jan 29 '15 #4
Thank you for your knowledge. Easiest method is to find the MySQL syntax that would allow me to do the same thing or build a dump table in Access that I can build the HKEY then use it to sort records. Again Thank You.
Jan 29 '15 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Kevin Shea | last post by:
I'm currently running into a problem with ie6 on a windows 2000 machine. I've developed a web application where the client, using JavaScript, opens up an ADODB.Recordset recordset and then reads...
0
by: elcc1958 | last post by:
I need to support a VB6 application that will be receiving disconnected ADODB.Recordset from out DotNet solution. Our dotnet solution deals with System.Data.DataTable. I need to populate a...
5
by: Simone | last post by:
Hello I hope you guys can help me. I am very new to ADO... I am creating a ADODB connection in a module and trying to access it from a command button in a form. Function fxEIDAssgn(plngEID As...
0
by: CFW | last post by:
I thought this was going to be easy but I'm missing something . . . I need to open an ADODB recordset using the recordset source for a list box on my for. When my form opens, the list box ADODB...
3
by: mark_aok | last post by:
Hi all, All I am trying to do is open a table, edit it, and then close it. But I am having the strangest error. Here is my code Dim i as integer Dim rs as adodb.recordset Set rs = new...
0
by: PCroser | last post by:
I have encountered a problem when querying a table. The query passed data into a recordset which should have resulted in many records but has returned EOF. After debugging the code the only...
1
by: sphinney | last post by:
All, I have a ADODB.Recordset in my Access 2002 project. I've been able to successfully add fields to the record set. According the the MS Access help files, I now must update the recordset to...
6
by: Oko | last post by:
I'm currently developing an MS Access Data Project (.adp) in MS Access 2002. One of the reports within the DB uses data that is Dynamic and cannot be stored on the SQL Server. To resolve this, I...
1
by: Kloj | last post by:
I have two queries in MS.Access, qry1 and qry2. qry1 is based on table1, qry1 has two fields i.e Qty and Product. qry2 is sum of qry1. qry2 has two fields i.e Sum_of_Qty and Product, qry2...
5
by: Digital Oatmeal | last post by:
I am trying to call a function from a text box on a subform that returns a summed total of a single calculated field. I need to reproduce this function in multiple subforms so it is encapsulated as...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.