Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Syntax error Expand / Collapse
Author
Message
Posted Tuesday, September 17, 2013 3:36 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, September 18, 2013 2:11 PM
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


Post #1495702
Posted Wednesday, September 18, 2013 9:14 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 7:01 AM
Points: 13,069, Visits: 11,909
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 Moden's 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)
Post #1495975
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse