| |

VerySource

 Forgot password?
 Register
Search
View: 967|Reply: 4

Problems when SQL Server applies BCP to export data

[Copy link]

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-3-17 09:30:01
| Show all posts |Read mode
BCP tool to export the results obtained during the execution of stored procedures
Error message:
SQLState = 37000, NativeError = 156
Error = [Microsoft] [ODBC SQL Server Driver] [SQL Server] There is a syntax error near the keyword 'where'.

Situation description:
The above error only appeared on the client's machine, and it did not appear on my own machine or my colleague's machine, or even on my home machine.

Error BCP statement: bcp "exec vms.dbo. Vehicle operation_proc" queryout "e:\una\1\driverrecover.xml" -w -T

The view statements used:
CREATE VIEW dbo. Yesterday's driving record_v AS
SELECT DISTINCT
      Date, serial number, route name, license plate number, driver serial number, flight attendant serial number, departure time, arrival time, creator,
      Creation time
FROM dbo. Vehicle driving records
WHERE (SUBSTRING (CONVERT (char, date, 100), 7, 4) = YEAR (DATEADD ([day],-1,
      GETDATE ()))) AND (SUBSTRING (CONVERT (char, date, 100), 1, 2)
      = MONTH (DATEADD ([day],-1, GETDATE ()))) AND (SUBSTRING (CONVERT (char, date,
      100), 4, 2) = DAY (DATEADD ([day],-1, GETDATE ())))

Stored procedure statements used:
create proc vehicle operation_proc as select 1 as tag,
       null as parent,
       null as [root! 1 !! element],
       null as [steerrecover! 2! number],
       null as [steerrecover! 2! date],
       null as [steerrecover! 2! line],
       null as [steerrecover! 2! busnumber],
       null as [steerrecover! 2! drivernumber],
       null as [steerrecover! 2! stewardnumber],
       null as [steerrecover! 2! leavetime],
       null as [steerrecover! 2! arrivetime],
       null as [steerrecover! 2! creator],
       null as [steerrecover! 2! createtime],
       null as [steerrecover! 2! mendir],
       null as [steerrecover! 2! fixtime],
       null as [ticket! 3! ticketnumber],
       null as [ticket! 3! leavestation],
       null as [ticket! 3! arrivestation],
       null as [ticket! 3! price],
       null as [ticket! 3! amount]
from
vms.dbo. Yesterday's driving record_v a
union
select 2,
        1,
        null,
a. serial number,
a. date,
a. route name,
a. license plate number,
a. driver serial number,
a. Flight attendant serial number,
a. departure time,
a. arrival time,
a. creator,
a. creation time,
a. Modified by,
a. modification time,
null,
null,
null,
null,
null
from
vms.dbo. Yesterday's driving record_v a
union
select 3,
        2,
        null,
a. serial number,
a. date,
a. route name,
a. license plate number,
a. driver serial number,
a. Flight attendant serial number,
a. departure time,
a. arrival time,
a. creator,
a. creation time,
a. Modified by,
a. modification time,
b. serial number,
b. departure station,
b. arrive at the site,
b. price,
b. votes
from
vms.dbo. Yesterday's driving record_v a left join vms.dbo.Ticketing record b on a. Serial number = b. Driving record Serial number
order by [steerrecover! 2! number], [ticket! 3! ticketnumber]

for xml explicit



I ask for your help! !! !!
Reply

Use magic Report

0

Threads

9

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 United States

Post time: 2020-7-11 20:45:01
| Show all posts
Is there any error in direct execution in Query Analyzer?
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 United States

 Author| Post time: 2020-7-22 18:00:02
| Show all posts
An error occurred while executing BCP. Whether in query analyzer or DOS
Reply

Use magic Report

0

Threads

30

Posts

25.00

Credits

Newbie

Rank: 1

Credits
25.00

 China

Post time: 2020-7-24 13:15:01
| Show all posts
Since there is a syntax error near the keyword'where'
Try to remove it
WHERE (SUBSTRING(CONVERT(char, date, 100), 7, 4) = YEAR(DATEADD([day],-1,
      GETDATE()))) AND (SUBSTRING(CONVERT(char, date, 100), 1, 2)
      = MONTH(DATEADD([day],-1, GETDATE()))) AND (SUBSTRING(CONVERT(char, date,
      100), 4, 2) = DAY(DATEADD([day],-1, GETDATE())))
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-7-28 11:30:01
| Show all posts
Thank you, let me see if I have a chance to try it.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list