Solved

Incorrect syntax near the keyword 'where'.

Posted on 2011-03-16
3
461 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
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:ewangoya
ewangoya 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Suggested Solutions

by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

856 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