Solved

VB6 SQL query problem

Posted on 2008-06-11
2
1,129 Views
Last Modified: 2010-04-21
I am using VB to get data from a Microsoft SQL database. I used Microsoft Query to generate a SQL statement. The query ran perfectly in Microsoft Query. But when I used it in my application it returned this error message.
Run-time error '-2147217900 (80040e14)': [Microsoft][ODBC SQL Server] Invalid column name 'C'.

I have tried other queries which work correctly. It seems to be the last bit that causes the problem
AND ((bmwohm.status <> ""C""))"
---Microsoft Query---
SELECT rl_lot.works_order, rl_lot.line_no, rl_lot.lot, rl_lot.expiry, bmwohm.status
FROM cs3live.scheme.bmwohm bmwohm, cs3live.scheme.rl_lot rl_lot
WHERE bmwohm.works_order = rl_lot.works_order AND ((bmwohm.status<>"C"))
 
---Code used in VB---
SQL = "SELECT rl_lot.works_order, rl_lot.line_no, rl_lot.lot, rl_lot.expiry " & _
                "FROM cs3live.scheme.bmwohm bmwohm, cs3live.scheme.rl_lot rl_lot " & _
                "WHERE bmwohm.works_order = rl_lot.works_order AND ((bmwohm.status <> ""C""))"

Open in new window

0
Comment
Question by:Randox_Laboratories
2 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 500 total points
ID: 21758211
Hello Randox_Laboratories,

Because you either need to include "Set QUOTED_IDENTIFIER ON" in your statement or use single quotes instead (the latter is easier!)

   SQL = "SELECT rl_lot.works_order, rl_lot.line_no, rl_lot.lot, rl_lot.expiry " & _
                   "FROM cs3live.scheme.bmwohm bmwohm, cs3live.scheme.rl_lot rl_lot " & _
                   "WHERE bmwohm.works_order = rl_lot.works_order AND ((bmwohm.status <> 'C'))"

Regards,

TimCottee
0
 
LVL 1

Author Closing Comment

by:Randox_Laboratories
ID: 31466077
Thanks, that worked great.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question