Solved

Error Incorrect syntax near the keyword 'outer'.

Posted on 2006-11-13
10
998 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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 500 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Filter Question 8 82
Forcing form refresh - classic ASP 7 66
Need help to rewrite script 3 79
Save ms data to server side. 19 43
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

776 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