Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Incorrect syntax near the keyword 'where'.

Posted on 2011-03-16
3
Medium Priority
?
491 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 1000 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 1000 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Loops Section Overview

926 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