gpt4 book ai didi

mysql - 将查询导出到 Excel

转载 作者:行者123 更新时间:2023-11-30 21:34:39 26 4
gpt4 key购买 nike

我正在尝试将查询结果导出到 csv 文件,但出于某种原因,我从 SQL Server 收到此错误:

Msg 156, Level 15, State 1, Line 32
Incorrect syntax near the keyword 'INTO'

我不知道为什么或如何解决这个问题。

WITH q AS
(
SELECT
A.ExternalID,
Sheet = A.UserDefinedXml.value('(//SkinSheet/@Label)[1]', 'varchar(3)'),
LOA_Request_Sent = A.UserDefinedXml.value('(//SentDate/@Value)[1]', 'varchar(12)'),
LOA_Received = A.UserDefinedXml.value('(//ReceivedDate/@Value)[1]', 'varchar(12)'),
LOA_Discontinued_Date = A.UserDefinedXml.value('(//DicontinuedDate/@Value)[1]', 'varchar(12)'),
LOA_Disc_Reason = A.UserDefinedXml.value('(//ReasonDiscontinued/@Value)[1]', 'VARCHAR(MAX)'),
LOA_InsuranceStatus = A.UserDefinedXml.value('(//InsuranceStatus/@Label)[1]', 'VARCHAR(MAX)'),
LOA_NoOONIns = A.UserDefinedXml.value('(//NoOONBenefitsInsCompany/@Value)[1]', 'VARCHAR(MAX)'),
LOA_NotMedNecIns = A.UserDefinedXml.value('(//NotMedNecessaryInsCompany/@Value)[1]', 'VARCHAR(MAX)'),
LOA_FacilityRefused = A.UserDefinedXml.value('(//FacilityRefused/@Value)[1]', 'varchar(5)'),
LOA_OtherDenial = A.UserDefinedXml.value('(//ReasonDenied/@Value)[1]', 'varchar(5)'),
LOA_OtherDenialReason = A.UserDefinedXml.value('(//OtherReasonDenied/@Value)[1]', 'varchar(max)'),
AuthorizationReceived = A.UserDefinedXml.value('(//AuthorizationToTreatReceivedDate/@Value)[1]','varchar(12)'),
POReceived = A.UserDefinedXml.value('(//POReceivedDate/@Value)[1]', 'varchar(12)'),
ICRecieved = A.UserDefinedXml.value('(//InformedConsentReceivedDate/@Value)[1]', 'varchar(12)'),
A.ServiceSiteUid,
A.LastModifiedDate,
PersonUid_A = A.PersonUid,
B.FirstName, B.LastName,
PersonUid_B = B.PersonUid,
C.Name
FROM
Patient A
INNER JOIN
Person B ON B.PersonUid = A.PersonUid
INNER JOIN
ListServiceSite C ON C.ServiceSiteUid = A.ServiceSiteUid
)
SELECT
Name, ExternalID, FirstName, LastName, POReceived,
ICRecieved, AuthorizationReceived, LOA_Request_Sent, LOA_Received,
LOA_FacilityRefused, LOA_OtherDenial, Sheet
FROM
q
WHERE
Sheet = 'Yes'
INTO OUTFILE 'C:\Users\Intern\Desktop\Sheet.csv'
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n';

最佳答案

Into 在 from 子句之前:

  SELECT Name, ExternalID, FirstName, LastName, POReceived, ICRecieved, AuthorizationReceived, LOA_Request_Sent, LOA_Received, LOA_FacilityRefused, LOA_OtherDenial, Sheet 
INTO OUTFILE 'C:\Users\Intern\Desktop\Sheet.csv'
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n';
FROM q
WHERE Sheet = 'Yes'

关于mysql - 将查询导出到 Excel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54593988/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com