Solved

Incorrect syntax near the keyword 'where'.

Posted on 2011-03-16
3
475 Views
Last Modified: 2012-05-11

thjs works but I want to add a line at the bottom
where orderid!=0 and orderid!=7001951



Select distinct p1.orderid
from [dbo].[payments] p1
inner join [dbo].[payments] p2
on p1.orderid = p2.orderid and p1.debit = p2.debit
WHERE
p1.resultcode='completed' and
p2.resultcode='confirmed'






when I do, I get error

Select distinct p1.orderid
from [dbo].[payments] p1
inner join [dbo].[payments] p2
on p1.orderid = p2.orderid and p1.debit = p2.debit
WHERE
p1.resultcode='completed' and
p2.resultcode='confirmed'


where orderid!=0 and orderid!=7001951


Msg 156, Level 15, State 1, Line 8
Incorrect syntax near the keyword 'where'.

0
Comment
Question by:rgb192
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 9

Accepted Solution

by:
AriMc earned 250 total points
ID: 35152439
You can not have to where clauses. Combine them with the and operator:

Select distinct p1.orderid
from [dbo].[payments] p1
inner join [dbo].[payments] p2
on p1.orderid = p2.orderid and p1.debit = p2.debit
WHERE
p1.resultcode='completed' and
p2.resultcode='confirmed'
and p1.orderid<>0 and p1.orderid<>7001951

Open in new window

0
 
LVL 32

Assisted Solution

by:Ephraim Wangoya
Ephraim Wangoya earned 250 total points
ID: 35152441

use and


Select distinct p1.orderid
from [dbo].[payments] p1
inner join [dbo].[payments] p2
on p1.orderid = p2.orderid and p1.debit = p2.debit
WHERE p1.resultcode='completed'
and p2.resultcode='confirmed'
and  orderid != 0
and orderid != 7001951
0
 

Author Closing Comment

by:rgb192
ID: 35152466
thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

734 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