Msg 102, Level 15, State 1, Server WCS\INHANCE, Line 1 Incorrect syntax near 'account_num'

I have a sql script that I run in MS SQL Server 2012 SSMS that works fine. When I try to run the command in a batch file using sqlcmd i get this error Msg 102, Level 15, State 1, Server WCS\INHANCE, Line 1
Incorrect syntax near 'account_num'.

Here is the command:
SELECT "ub_customer"."account_num", "ub_customer"."status", "ub_meter"."meter_num", "ub_customer"."billing_cycle_id", "ub_customer"."first_name", "ub_customer"."surname", "ub_customer"."alt_name", "ub_service_location"."building_id", "ub_service_location"."prefix", "ub_street"."street_name", "ub_vw_service_location"."city", "ub_vw_service_location"."state", "ub_vw_service_location"."postal_code", "vw_customer"."Class", "vw_income"."RateCode", "vw_income"."income_id", "vw_income"."Description", "ub_meter"."usage_multiplier", "ub_measure"."measure_descr", "ub_customer"."home_phone_num", "ub_customer"."cell_phone_num", "vw_mailing_address"."Address_line_1", "vw_mailing_address"."Address_line_2", "vw_mailing_address"."Address_line_3", "vw_mailing_address"."City", "vw_mailing_address"."State", "vw_mailing_address"."Zip", "ub_group_meter"."use_method", "vw_meter"."MeterSize", "ub_vw_service_location"."owner_id", "vw_location"."Usage01", "vw_location"."Usage02", "ub_meter"."serial_num"
FROM (("oasis"."dbo"."vw_mailing_address" "vw_mailing_address" INNER JOIN ((((((((("oasis"."dbo"."ub_group_meter" "ub_group_meter" INNER JOIN "oasis"."dbo"."ub_group_name" "ub_group_name" ON "ub_group_meter"."group_id"="ub_group_name"."group_id") INNER JOIN "oasis"."dbo"."vw_income" "vw_income" ON ("ub_group_meter"."location_id"="vw_income"."location_id") AND ("ub_group_meter"."group_id"="vw_income"."group_id")) INNER JOIN "oasis"."dbo"."ub_meter" "ub_meter" ON ("ub_group_meter"."meter_id"="ub_meter"."meter_id") AND ("ub_group_meter"."location_id"="ub_meter"."location_id")) INNER JOIN "oasis"."dbo"."ub_service_location" "ub_service_location" ON ("ub_group_meter"."location_id"="ub_service_location"."location_id") AND ("ub_meter"."location_id"="ub_service_location"."location_id")) INNER JOIN "oasis"."dbo"."ub_measure" "ub_measure" ON "ub_group_name"."bill_measure_id"="ub_measure"."measure_id") INNER JOIN "oasis"."dbo"."vw_meter" "vw_meter" ON "ub_meter"."meter_id"="vw_meter"."meter_id") INNER JOIN "oasis"."dbo"."ub_customer" "ub_customer" ON "ub_service_location"."customer_id"="ub_customer"."customer_id") LEFT OUTER JOIN "oasis"."dbo"."ub_street" "ub_street" ON "ub_service_location"."street_id"="ub_street"."street_id") LEFT OUTER JOIN "oasis"."dbo"."ub_vw_service_location" "ub_vw_service_location" ON "ub_service_location"."location_id"="ub_vw_service_location"."location_id") ON "vw_mailing_address"."customer_id"="ub_customer"."customer_id") LEFT OUTER JOIN "oasis"."dbo"."vw_customer" "vw_customer" ON "ub_customer"."customer_id"="vw_customer"."customer_id") LEFT OUTER JOIN "oasis"."dbo"."vw_location" "vw_location" ON "ub_vw_service_location"."location_id"="vw_location"."location_id"
WHERE "ub_meter"."meter_num"<>'isnull' AND "ub_customer"."status"='A' AND ("ub_customer"."billing_cycle_id"=1 OR "ub_customer"."billing_cycle_id"=6)
ORDER BY "ub_customer"."billing_cycle_id", "ub_customer"."account_num", "ub_meter"."meter_num", "vw_income"."income_id"

Any help would be appreciated.

Try removing all of the double quotes. Looks like there's a few extra parentheses too. I'm guessing this query was written by a query designer.

the default is probably QUOTED_IDENTIFIER OFF ?

try putting

SET QUOTED_IDENTIFIER ON

at the begining of the script

1 Like

Thank you. Adding SET QUOTED_IDENTIFIER ON fixed the problem.

Did not try removing the quotes as the next solution fixed the problem. And yes the finance dept submitted this from a query designer.

The double quotes and all of those unneeded parenthesis is how I knew it was the query designer. It writes unreadable queries and often bad queries. I just fire open a new query window and start typing.