• 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 http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/