Click here to Skip to main content
16,004,898 members
Home / Discussions / Database
   

Database

 
Questionhierarchy Pin
mehrdadc4828-Sep-09 4:42
mehrdadc4828-Sep-09 4:42 
AnswerRe: hierarchy Pin
J4amieC28-Sep-09 5:36
J4amieC28-Sep-09 5:36 
AnswerRe: hierarchy Pin
i.j.russell28-Sep-09 10:56
i.j.russell28-Sep-09 10:56 
QuestionXML Column in SQL Server 2005 Pin
Kartik Kumar28-Sep-09 0:02
Kartik Kumar28-Sep-09 0:02 
QuestionSSRS - Web Service vs URL access Pin
devvvy27-Sep-09 21:36
devvvy27-Sep-09 21:36 
AnswerRe: SSRS - Web Service vs URL access Pin
r a m e s h29-Sep-09 0:21
r a m e s h29-Sep-09 0:21 
GeneralRe: SSRS - Web Service vs URL access Pin
devvvy29-Sep-09 0:24
devvvy29-Sep-09 0:24 
QuestionNo error from SSMS but from applciation [modified] ------ Never mind, solved Pin
Mustafa Ismail Mustafa26-Sep-09 9:58
Mustafa Ismail Mustafa26-Sep-09 9:58 
Turns out I was specifying the length of the XML string from the application. Goes to show how dumb one can be sometimes!

This error has been driving me mad.   Testing the whole run from within SSMS using the same values that are provided by the application yields a perfectly working result; The application itself returns "XML parsing: line 1, character 4, unexpected end of input"

The actual XML being sent is:
<Data>
   <AssignedDiet>
      <PatientID>127686419</PatientID>
      <AdmittanceID>3</AdmittanceID>
      <DietID>1</DietID>
      <Notes></Notes>
   </AssignedDiet>
</Data>


The stored procedure called is:

&lt;pre&gt;
------------------------------------------------------------------------------------------------------------------------
-- Author:&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;   Mustafa Ismail Mustafa
-- Procedure Name: [EMR].[NV_VW_Orders_Diet_Insert]
-- Date Generated: Sunday, August 09, 2009
-- Company:&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; Netvareas Solutions
-- Project Name:&nbsp;&nbsp;   RCH Automation
------------------------------------------------------------------------------------------------------------------------

ALTER PROCEDURE [EMR].[NV_VW_Orders_Diet_Insert]

@PatientID char(10),
@AdmittanceID int,
@IssuingEmployeeID int,
@DateTimeGiven datetime,
@OrderDetails nvarchar(max),
@IsDoctor bit,
@IsCanceled bit,
@IsCompleted bit,
@ClosingEmployeeID int,
@ClosingDateTime datetime,
@IsRepeated bit,
@IsDefaultTime bit,
@DefaultTimeID int,
@PeriodID int,
@PeriodValue int,
@Notes nvarchar(max),
@DietID int,
@OrderType nvarchar(50),
@Tags XML,
@SubOrderID int OUTPUT,
@OrderID int OUTPUT

AS

SET NOCOUNT ON

BEGIN TRANSACTION

/*

1. Retrieve the SubOrderID (Max current DietOrderID + 1)
2. Insert the PatientOrder and retrieve the OrderID
3. Insert the DietOrder
4. Extract from the XML all the rows to be inserted into mmPatientDiets
5. Insert rows into the persistant table mmPatientDiets

*/

DECLARE @ERR int = 0;

--1.
SET @SubOrderID = ISNULL((SELECT MAX(DietOrderID) FROM EMR.PatientAssignedDiets WHERE PatientID = @PatientID AND AdmittanceID = @AdmittanceID),0) + 1;


--2.
EXEC [EMR].[NV_PatientOrders_Insert]
&nbsp;&nbsp;&nbsp;&nbsp; @PatientID,&nbsp;&nbsp;&nbsp;&nbsp; @AdmittanceID,&nbsp;&nbsp;&nbsp;&nbsp; @DateTimeGiven,&nbsp;&nbsp;&nbsp;&nbsp; @IssuingEmployeeID,&nbsp;&nbsp;&nbsp;&nbsp; @OrderDetails,&nbsp;&nbsp;&nbsp;&nbsp; @IsDoctor,&nbsp;&nbsp;&nbsp;&nbsp; @IsCanceled,
&nbsp;&nbsp;&nbsp;&nbsp; @IsCompleted,&nbsp;&nbsp;&nbsp;&nbsp; @IsRepeated,&nbsp;&nbsp;&nbsp;&nbsp; @IsDefaultTime,&nbsp;&nbsp;&nbsp;&nbsp; @DefaultTimeID,&nbsp;&nbsp;&nbsp;&nbsp; @PeriodID,&nbsp;&nbsp;&nbsp;&nbsp; @PeriodValue, @OrderType,
&nbsp;&nbsp;&nbsp;&nbsp; @SubOrderID, @OrderID OUTPUT

SET @ERR = (SELECT @@ERROR)
if @ERR &amp;lt;&amp;gt; 0
&nbsp;&nbsp;&nbsp;&nbsp; GOTO ErrorHandler
--3.
EXEC [EMR].[NV_PatientAssignedDiets_Insert]&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp; @PatientID, @AdmittanceID, @OrderID, @SubOrderID

SET @ERR = (SELECT @@ERROR)
if @ERR &amp;lt;&amp;gt; 0
&nbsp;&nbsp;&nbsp;&nbsp; GOTO ErrorHandler

--4.
EXEC sp_xml_preparedocument @Handle OUTPUT, @Tags

SET @ERR = (SELECT @@ERROR)
if @ERR &amp;lt;&amp;gt; 0
&nbsp;&nbsp;&nbsp;&nbsp; GOTO ErrorHandler


--5.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;
INSERT INTO EMR.mmPatientDiets
&nbsp;&nbsp;&nbsp;&nbsp; SELECT PatientID, AdmittanceID,@OrderID,@SubOrderID, DietID, Notes, GETDATE(), null
&nbsp;&nbsp;&nbsp;&nbsp; FROM OPENXML (@Handle, '/Data/AssignedDiet', 2) WITH
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; (PatientID char(10), AdmittanceID int, DietID int, Notes nvarchar(max) );
&nbsp;&nbsp;&nbsp;&nbsp;
SET @ERR = (SELECT @@ERROR)
if @ERR &amp;lt;&amp;gt; 0
&nbsp;&nbsp;&nbsp;&nbsp; GOTO ErrorHandler

ErrorHandler:
IF @ERR &amp;lt;&amp;gt; 0
BEGIN
&nbsp;&nbsp;&nbsp;&nbsp; Rollback
&nbsp;&nbsp;&nbsp;&nbsp; RETURN @Err
END
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;
COMMIT
&lt;/pre&gt;



I don't know what else to post, but I'd be more than happy to oblige.&nbsp;&nbsp; What makes it absolutely annoying is that it works fine from SSMS!

TIA

If the post was helpful, please vote, eh!

Current activities:
Book: Devils by Fyodor Dostoyevsky
Project: Hospital Automation, final stage
Learning: Image analysis, LINQ

Now and forever, defiant to the end.
What is Multiple Sclerosis[^]?

modified on Saturday, September 26, 2009 4:45 PM

Questionrun date query in nvarchar type, how ? Pin
E_Gold26-Sep-09 8:25
E_Gold26-Sep-09 8:25 
AnswerRe: run date query in nvarchar type, how ? Pin
Luc Pattyn26-Sep-09 10:10
sitebuilderLuc Pattyn26-Sep-09 10:10 
AnswerRe: run date query in nvarchar type, how ? Pin
Mycroft Holmes26-Sep-09 15:07
professionalMycroft Holmes26-Sep-09 15:07 
GeneralRe: run date query in nvarchar type, how ? Pin
Luc Pattyn26-Sep-09 16:44
sitebuilderLuc Pattyn26-Sep-09 16:44 
GeneralRe: run date query in nvarchar type, how ? Pin
Mycroft Holmes26-Sep-09 17:51
professionalMycroft Holmes26-Sep-09 17:51 
GeneralRe: run date query in nvarchar type, how ? Pin
Richard MacCutchan26-Sep-09 22:00
mveRichard MacCutchan26-Sep-09 22:00 
Questiondatagridview in tabcontrol! Pin
jeshra27925-Sep-09 18:31
jeshra27925-Sep-09 18:31 
AnswerRe: datagridview in tabcontrol! Pin
Mycroft Holmes26-Sep-09 15:12
professionalMycroft Holmes26-Sep-09 15:12 
QuestionTake a databse back up with LINQ ? Pin
Mohammad Dayyan25-Sep-09 15:58
Mohammad Dayyan25-Sep-09 15:58 
AnswerRe: Take a databse back up with LINQ ? Pin
Not Active25-Sep-09 17:19
mentorNot Active25-Sep-09 17:19 
GeneralRe: Take a databse back up with LINQ ? Pin
Mohammad Dayyan25-Sep-09 17:26
Mohammad Dayyan25-Sep-09 17:26 
GeneralRe: Take a databse back up with LINQ ? Pin
Not Active26-Sep-09 5:05
mentorNot Active26-Sep-09 5:05 
GeneralRe: Take a databse back up with LINQ ? Pin
Abhishek Sur26-Sep-09 6:48
professionalAbhishek Sur26-Sep-09 6:48 
GeneralRe: Take a databse back up with LINQ ? Pin
Mohammad Dayyan26-Sep-09 7:54
Mohammad Dayyan26-Sep-09 7:54 
QuestionConvert scripts for Postgresql to SQL Server Pin
Not Active25-Sep-09 5:32
mentorNot Active25-Sep-09 5:32 
AnswerRe: Convert scripts for Postgresql to SQL Server Pin
Mycroft Holmes26-Sep-09 15:16
professionalMycroft Holmes26-Sep-09 15:16 
GeneralRe: Convert scripts for Postgresql to SQL Server Pin
Not Active26-Sep-09 15:21
mentorNot Active26-Sep-09 15:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.