Solved

Error Incorrect syntax near the keyword 'outer'.

Posted on 2006-11-13
10
997 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Round to 2 decimal places 2 40
Syntax Help on SP 4 57
How to solve this equation 3 52
RegEx Help - open to other simple suggestions 8 39
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

867 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now