Экспорт запроса в Excel - PullRequest
       37

Экспорт запроса в Excel

0 голосов
/ 08 февраля 2019

Я пытаюсь экспортировать результаты моего запроса в файл csv, но по какой-то причине я получаю эту ошибку от SQL Server:

Сообщение 156, Уровень 15, Состояние 1, Строка 32
Неверный синтаксис рядом с ключевым словом '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';

1 Ответ

0 голосов
/ 08 февраля 2019

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'
...