2014-01-16 52 views
1

當執行程序蔭面對錯誤XML分析:行1中,字符63,字符串文字預計

XML分析:行1中,字符63,字符串文字預計

`

DECLARE @return_value int 

EXEC @return_value = [dbo].[Icn_GetResultCountForAllAdvancedSearch] 
     @sqtype = 1, 
     @UserID = 615, 
     @AdvancedSearchQuery = N'<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<Searches xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\r\n <Search SearchId=\"2447\" Query=\" where ([FLD5283] IS NOT NULL and [FLD5283] &lt;&gt; '''') and 5263 IN (Select FieldID from Icn_ContractFieldsEntry icfe where icfe.ContractID=z1.ContractID) AND (Archive &lt;&gt;''true'' OR Archive is null)\" />\r\n <Search SearchId=\"2439\" Query=\" where ([FLD5399] IS NOT NULL and [FLD5399] &lt;&gt; '''')  AND (Archive &lt;&gt;''true'' OR Archive is null)\" />\r\n <Search SearchId=\"2386\" Query=\" where ([ContractId] IS NOT NULL and (case when CONVERT(varchar(max),[ContractId])='''' then ''0'' else [ContractId] end) &lt;&gt; (''0'')) AND (Archive &lt;&gt;''true'' OR Archive is null)\" />\r\n</Searches>' 

SELECT 'Return Value' = @return_value 

GO 

`

回答

2

文本你如下所示:

@AdvancedSearchQuery = N'<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<Searches ...>\r\n</Searches>' 

不是SQL Server知道如何處理的有效XML。 \"轉義讓人想起如何在C#字符串中轉義"字符。 SQL中的"不需要這種轉義,因爲它的字符串分隔符是'\r\n,類似地,看起來像C#(或C等)轉義序列,這在SQL服務器字符串中不受支持。

要在一個SQL字符串換行符,只要在適當的地方一個回車換行符不關閉字符串或字符串追加與CHAR(13) + CHAR(10) - 但使用這種第二種形式,你需要從調用單獨構建@AdvancedSearchQuery存儲過程 - 您可以在調用過程時傳遞參數或字符串文字,而不是表達式。