我有以下sql存储过程:
USE [FishTrackerProfessional]
GO
/****** Object: StoredProcedure [dbo].[CreateErsSalesAddSubmission] Script Date: 08/06/2015 15:57:42 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[CreateErsSalesAddSubmission]
-- Add the parameters for the stored procedure here
@uname VARCHAR(10) ,
@pword VARCHAR(10) ,
@sntype VARCHAR(1) ,
@action VARCHAR(10) ,
@salesContractRef VARCHAR(10),
@auctionId NCHAR(10)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT
RTRIM(@uname) AS '@uname',
RTRIM(@pword) AS '@pword',
(SELECT
@snType AS '@snType',
RTRIM(@action) AS '@action',
COALESCE(@salesContractRef, '') AS '@salesContractRef',
CONVERT(VARCHAR(10), DateOfPurchase, 112) AS '@saleDate',
RTRIM(COALESCE(@auctionID, '')) AS '@auctionID',
ISNULL(Logbook1 + ',', '') + ISNULL(Logbook2 + ',', '') + ISNULL(Logbook3 + ',', '') AS '@logBookNums',
ISNULL(LandingDecNumber1 + ',', '') + ISNULL(LandingDecNumber2 + ',', '') + ISNULL(LandingDecNumber3 + ',', '') AS '@landingDecNums',
COALESCE(VesselName, '') AS '@vesselName',
RTRIM(VesselPLN) AS '@vesselPln',
RTRIM(VesselOwner) AS '@vesselMasterOwner',
COALESCE(CONVERT(VARCHAR(10), LandingDate1, 112), '') AS '@landingDate1',
COALESCE(CONVERT(VARCHAR(10), LandingDate2, 112), '') AS '@landingDate2',
COALESCE(CONVERT(VARCHAR(10), LandingDate3, 112), '') AS '@landingDate3',
RTRIM(CountryOfLanding) AS '@countryOfLanding',
RTRIM(PortOfLanding) AS '@portOfLanding',
(SELECT
COALESCE(RTRIM(SpeciesCode),'') AS '@speciesCode',
RTRIM(FishingArea) AS '@faoAreaCode',
COALESCE(RTRIM(IcesZone),'') AS '@ZoneCode',
COALESCE(RTRIM(ld.DisposalCode),'') AS '@disposalCode',
COALESCE(ld.FreshnessGrade,'') AS '@freshnessCode',
COALESCE(ld.ProductSize,'') AS '@sizeCode',
COALESCE(ld.PresentationCode,'') AS '@presentationCode',
COALESCE(ld.PresentationState,'') AS '@stateCode',
RTRIM(ld.NumberOfFish) AS '@numberOfFish',
FORMAT(ld.Quantity, 'N2') AS '@weightKgs',
FORMAT(Quantity * ld.UnitPrice, 'N2') AS '@value',
COALESCE(ld.Currency,'') AS '@currencyCode',
RTRIM(ld.WithdrawnDestinationCode) AS '@withdrawnDestinationCode',
RTRIM(ld.BuyersRegistrationCode) AS '@buyerReg',
RTRIM(ld.SalesContractRef) AS '@salesContractRef'
FROM LandingDetails ld
JOIN LandingHeaders lh
ON ld.LandingId = lh.LandingId
WHERE ld.LandingId = lh1.LandingId
FOR XML PATH ('salesline'), TYPE)
FROM LandingHeaders lh1
WHERE lh1.AllocatedErsId IS NULL AND lh1.LandingDate1 BETWEEN '2015-05-01' AND '2015-05-30'
ORDER BY VesselName,lh1.LandingId
FOR XML PATH ('salesnote'), TYPE)
FOR XML PATH ('ers')
END
当从ssms内部运行时,它能够返回大量信息。但是,当这个过程被映射到我的entitydata模型中的一个函数时,返回一个类型为string的标量,它只返回它的一小部分。
我开始认为ssms是专门用于显示使用for xml的查询结果的,因此除非我可以做其他事情,否则这对我来说将是一个潜在的问题。
我知道我可以从ssms结果中保存此sproc的结果,并且它将全部保存到单个xml文件中。因此,可以从sproc中指示将结果保存到特定名称的文件中(例如公共文档文件夹之类的公共文件),并且在运行该过程时应始终覆盖它。
由于
答案 0 :(得分:0)
有可能,但我不确定它真的是个好主意。您的SQL Server用户帐户需要额外的权限才能写入磁盘,您需要管理和维护一种方法,以确保您不会无意中覆盖文件(哪些SQL编程实际上不是设计为以及,例如,.NET),你的过程的任何消费者都需要一些特殊的知识(这个过程在其他地方返回它的结果集,这里是它发生故障时发生的错误代码或发生故障等)。
您确实最好只是确保正确使用您的程序。对于EF,这个问题可能会有所帮助:Entity framework calling a FOR XML stored procedure truncates at 2033 characters
但请记住,其他一些(非EntityFramework)客户端可能有一天会想要使用该SP - 以绕过这个EF特定限制的方式重写它可能会让这个消费者陷入困境,需要进一步的体操应该首先由EF客户端执行。或者,只需使用ADO.NET而不是EF来调用该过程 - 在我看来,在这种情况下执行此操作可能比尝试解决奇怪的EF限制更容易。