Solved

Incorrect syntax near the keyword 'where'.

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

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 …
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

777 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