Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I get the following message when I try to enter the SQL statement in an SQL table:
Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'ORDER'.

SELECT Part_Number, Supplier, Inspected_By, Reason_For_Inspection, Date_Inspected, Shift, Supplier_Lot_Number, Made_Date, Made_Date_Text, Carton_Box_Serial_Number," & vbCrLf & " Total_Time, Qty_Received, Qty_Inspected, Qty_Rejected, Repair_Qty, Repair_Reason, Supplier_IPP_Number, Supplier_IPP_Description, Index_Number, Location, Comments, c004, c005, c007, c008, " & vbCrLf & " c009, c010, c013, c015, c018, c021, c022, c023, c024, c025, c027, c029, c031, c032, c033, c037, c048, c050, c052, c053, c054, c059, c060, c062, c064, c066, c067p, c069, c070, c072, c073, " & vbCrLf & " c074, c076, c077, c078, c079, c082, c083, c085, c086, c091, c094, c095, c096, c097, c098, c099, c100, c102, c103, c104, c105, c106, c107, c109, c110, c111, c113, c116, c117, c118, c120, " & vbCrLf & " c122, c123, c125, c126, c129, c132, c145, c148, c149, c151, c152, c154, c155, c156, c157, c158, c159, c160, c161, c162, c163, c164, c999, Time_Entered FROM Sort_Input WHERE ((Date_Inspected >= CAST('01/01/2014' as Datetime) AND Date_Inspected <= CAST('07/01/2016' as Datetime) AND Inspected_By ='khavens') ORDER BY Part_Number DESC, Inspected_By, Date_Inspected DESC;

What I have tried:

Changing position of '"' and ")".
Posted
Updated 1-Jul-16 12:00pm

1 solution

Using SQLFormat - Online SQL Formatter[^]
you get
SQL
...
FROM Sort_Input
WHERE ((Date_Inspected >= CAST('01/01/2014' AS Datetime)
        AND Date_Inspected <= CAST('07/01/2016' AS Datetime)
        AND Inspected_By ='khavens')
ORDER BY Part_Number DESC,
         Inspected_By,
         Date_Inspected DESC;

and you see that after WHERE you need only 1 ( instead of 2.
 
Share this answer
 
Comments
Karthik_Mahalingam 2-Jul-16 8:08am    
5! for the link provided
Patrice T 2-Jul-16 13:16pm    
Thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900