?
Solved

Error Incorrect syntax near the keyword 'outer'.

Posted on 2006-11-13
10
Medium Priority
?
1,019 Views
Last Modified: 2006-11-18
Error:
Microsoft OLE DB Provider for SQL Server error '80040e14'
Incorrect syntax near the keyword 'outer'.
/z4/1/lbl2.asp, line 27

Code:
<%'CONNECTION
Set conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Provider=SQLOLEDB; Data Source=localhost; Initial Catalog=001; User ID=; Password="
Set ObjRs = Server.CreateObject("ADODB.Recordset")
'DECLARATIONS
dim dia, strSQL, rs, strSQL1, rs1, ordno, strSQL2, strSQL3, rs3, strSQL4, rs4, znToAdd, strSQL5, srl
dia = Date()
ordno= Request.QueryString("ordno")
  strSQL = "Select * from (SELECT " &_
                  "ltrim(rtrim(s.ord_no)) as order_no," &_
                  "ltrim(rtrim(i.user_def_fld_1)) as eng_no, " &_
                  "ltrim(rtrim(i.user_def_fld_2)) as export2," &_
                  "ltrim(rtrim(i.user_def_fld_3)) as label," &_
                  "ltrim(rtrim(i.user_def_fld_4)) as cust," &_
                  "ltrim(rtrim(i.user_def_fld_5)) as cust_no " &_
                  "FROM sfordfil_sql s " &_
                  "left outer join imitmidx_sql i " &_
                  "on s.item_no = i.item_no) as tab1 " &_
                  "INNER JOIN " &_
                  "(SELECT ltrim(rtrim(ser_lot_no)) as ser_no, " &_
                  "l.* FROM labels l" &_
                  "right outer join imlsmst_sql q " &_
                  "on l.sf_ord = q.orig_ord_no) as tab2" &_
                  "ON tab1.order_no = tab2.sf_ord" &_
                  "where tab1.order_no = '& ordno & '"
  set rs = Conn.Execute(strSQL)                                                                       <--- This is Line 27
  znToAdd = RS("zn_4") + 1
%>

When I run in SQL Profiler it works.
0
Comment
Question by:kwitcom
  • 6
  • 4
10 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 17929748
Hi kwitcom,

               "l.* FROM labels l" &_
               "right outer join imlsmst_sql q " &_

These two lines become l.* FROM labels lright outer join ... you need a space in there

               "l.* FROM labels l " &_
               "right outer join imlsmst_sql q " &_


Tim Cottee
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 17929752
kwitcom,

>             "on l.sf_ord = q.orig_ord_no) as tab2" &_
>                "ON tab1.order_no = tab2.sf_ord" &_
>                "where tab1.order_no = '& ordno & '"

You will also need some here as well otherwise you will get other errors!

Tim
0
 

Author Comment

by:kwitcom
ID: 17929902
Now I get:
error '80020009'
/z4/1/lbl2.asp, line 28

Line is 28 is:
  znToAdd = RS("zn_4") + 1
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
LVL 43

Expert Comment

by:TimCottee
ID: 17929944
TimCottee,

zn_4 doesn't appear to be a field name in the returned recordset. What table is it in?

Tim
0
 

Author Comment

by:kwitcom
ID: 17929993
labels and it does come back in SQl Profiler.
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 17930037
kwitcom,

Ok, it could be that although it is there, it either conflicts with another field name or for some reason gets a different identifier. This does sometimes happen with complex queries. Could you first of all try a simple test to show all the field names you get out of the query:

For intField = 0 to rs.fields.count - 1
    Response.write (intfield & " : " & rs(intfield).name & " = " & rs(intfield).value & "<br />")
next

This will show you the field index, name and current value (assuming there are records returned) for the first record. Given that we can work out whether it has changed the fieldname or not.

Tim
0
 

Author Comment

by:kwitcom
ID: 17930130
Error:
ADODB.Field error '800a0bcd'
Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.
/z4/1/lbl2.asp, line 29

Code:
<%'CONNECTION
Set conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Provider=SQLOLEDB; Data Source=localhost; Initial Catalog=001; User ID=; Password="
Set ObjRs = Server.CreateObject("ADODB.Recordset")

'DECLARATIONS
dim dia, strSQL, rs, strSQL1, rs1, ordno, strSQL2, strSQL3, rs3, strSQL4, rs4, znToAdd, strSQL5, srl
dia = Date()
ordno= Request.QueryString("ordno")
  strSQL = "Select * from (SELECT " &_
                  "ltrim(rtrim(s.ord_no)) as order_no, " &_
                  "ltrim(rtrim(i.user_def_fld_1)) as eng_no, " &_
                  "ltrim(rtrim(i.user_def_fld_2)) as export2, " &_
                  "ltrim(rtrim(i.user_def_fld_3)) as label, " &_
                  "ltrim(rtrim(i.user_def_fld_4)) as cust, " &_
                  "ltrim(rtrim(i.user_def_fld_5)) as cust_no " &_
                  "FROM sfordfil_sql s " &_
                  "left outer join imitmidx_sql i " &_
                  "on s.item_no = i.item_no) as tab1 " &_
                  "INNER JOIN " &_
                  "(SELECT ltrim(rtrim(ser_lot_no)) as ser_no, " &_
                  "l.* FROM labels l " &_
                  "right outer join imlsmst_sql q " &_
                  "on l.sf_ord = q.orig_ord_no) as tab2 " &_
                  "ON tab1.order_no = tab2.sf_ord " &_
                  "where tab1.order_no = '& ordno & '"
  set rs = Conn.Execute(strSQL)
For intField = 0 to rs.fields.count - 1
    Response.write (intfield & " : " & rs(intfield).name & " = " & rs(intfield).value & "<br />")                                    <---Line with Error
next
  znToAdd = RS("zn_4") + 1
%>
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 2000 total points
ID: 17930172
kwitcom,

Ok, so that is implying that we don't get any records back from the query. If we did then there would be some field names shown. This is likely to be the cause of the previous error even though it didn't actually say so. If you are getting records returned in query analyzer, but not with the query here then there has to be something different that is causing this.

What is the format of the ordno variable? Is it numeric or a character string? If it is a string then that could be the problem, in fact there it is. Just as I was looking at it again I noticed that you haven't quoted that last line correctly, it should be:

               "where tab1.order_no = '" & ordno & "'"

Otherwise it was trying to find records where tabl1.order_no = '& ordno &' which is obviously never going to work!

Tim
0
 

Author Comment

by:kwitcom
ID: 17930191
Worked:
0 : order_no = 6091
1 : eng_no = 1002-PR-P-MA-ST-53
2 : export2 = 1
3 : label = 2
4 : cust = GCS
5 : cust_no =
6 : ser_no = 06450268
7 : sf_ord = 6091
8 : zn_1 = 1
9 : zn_1dt = 11/9/2006 7:01:02 AM
10 : zn_2 = 0
11 : zn_2dt =
12 : zn_3 = 0
13 : zn_3dt =
14 : zn_4 = 2
15 : zn_4dt = 11/10/2006 11:07:40 AM
16 : fnh_dt = 11/10/2006
17 : mdl_n = 10202-PR
18 : sn_1 = 06450268
19 : mdl_detail = 1002-PR-P-MA-ST-53
20 : status = 4
21 : doc = 1
22 : doc_dt = 11/9/2006 7:01:04 AM
23 : doc_prt_by =
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 17930221
kwitcom,

So now you can go back and use the rs(zn_4)+1 line as you were going to and hopefully you should get it working now. It looks like it was that incorrectly quoted line that was throwing it out.

Tim
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

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

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
The video provides a quick and easy steps to migrate MBOX file to well known Outlook PST and Office 365. Besides this, it also supports and migrates more than 20 email clients of MBOX which include AppleMail, Opera, Thunderbird and SeaMonkey effortl…
Hi, this video explains a free download that you can incorporate into your Access databases, or use stand-alone for contact management. Contacts -- Names, Addresses, Phone Numbers, eMail Addresses, Websites, Lists, Projects, Notes, Attachments…

601 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