SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Syntax error


Syntax error

Author
Message
slammbo.ho
slammbo.ho
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 4
I'm just learning SQL and not very good at it yet. Trying to self teach so it's been slow. So I tried to duplicate this sql from our old database to our new one and I get this error. It works fine in the old but not the new. Any help would be appreciated. Thanks!

Msg 156, Level 15, State 1, Line 22
Incorrect syntax near the keyword 'FROM'.
Msg 156, Level 15, State 1, Line 36
Incorrect syntax near the keyword 'AND'.

SELECT
ID,ShipTo,ShipToID,ShipToCompany,BillTo,BillToCompany,PaymentType,DateCreated,EmployeeID,Type,Frequency,CCPartial
FROM
Aptify.dbo.vwStandingOrders

WHERE --- we'll only study active future fulfillments
(Status LIKE 'Active' AND
(DateExpires > GETDATE() OR DateExpires < '1/2/1901')
)
AND
ID IN -- find only stabding orders for dues products
(SELECT StandingOrderID FROM vwStandingOrProd sop
inner join vwProducts prod on sop.productID=prod.id
AND prod.categoryID IN(1,8,9,10,11)
)

AND PaymentTypeID IN (11,12,18,19,20,21,22,26,27,28,29)
and ( (isNull( PONumber, '' ) = '' ) OR (isNull( Terms , '' ) = '' ) )

ORDER BY Aptify.dbo.vwStandingOrders.[DateCreated] DESC

FROM
Aptify.dbo.vwStandingOrders

WHERE --- we'll only study active future fulfillments
(Status LIKE 'Active' AND
(DateExpires > GETDATE() OR DateExpires < '1/2/1901')
)
AND
ID IN -- find only stabding orders for dues products
(SELECT StandingOrderID FROM vwStandingOrProd sop
inner join vwProducts prod on sop.productID=prod.id
AND prod.categoryID IN(1,8,9,10,11)
)

AND PaymentTypeID IN (11,12,18,19,20,21,22,26,27,28,29)
and ( (isNull( PONumber, '' ) = '' ) OR (isNull( Terms , '' ) = '' ) )

ORDER BY Aptify.dbo.vwStandingOrders.[DateCreated] DESC
Sean Lange
Sean Lange
SSC Guru
SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)

Group: General Forum Members
Points: 62439 Visits: 17954
It looks like you have pasted a portion of your query a second time. Look where the first ORDER BY is, you then have FROM ... the same sql as before it.

Total shot in the dark but maybe this is what you are looking for. BTW, I ran this through a formatter so it is legible.




SELECT ID
,ShipTo
,ShipToID
,ShipToCompany
,BillTo
,BillToCompany
,PaymentType
,DateCreated
,EmployeeID
,Type
,Frequency
,CCPartial
FROM Aptify.dbo.vwStandingOrders
WHERE --- we'll only study active future fulfillments
(
STATUS LIKE 'Active'
AND (
DateExpires > GETDATE()
OR DateExpires < '1/2/1901'
)
)
AND ID IN -- find only stabding orders for dues products
(
SELECT StandingOrderID
FROM vwStandingOrProd sop
INNER JOIN vwProducts prod ON sop.productID = prod.id
AND prod.categoryID IN (
1
,8
,9
,10
,11
)
)
AND PaymentTypeID IN (
11
,12
,18
,19
,20
,21
,22
,26
,27
,28
,29
)
AND (
(isNull(PONumber, '') = '')
OR (isNull(Terms, '') = '')
)
ORDER BY Aptify.dbo.vwStandingOrders.[DateCreated] DESC




_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search