Solved

Incorrect syntax near the keyword 'where'.

Posted on 2011-03-16
3
431 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 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

13 Experts available now in Live!

Get 1:1 Help Now