This is the stored procedure I'm using to get 5 digits from an xml:
CREATE PROCEDURE [dbo].[SP_KINGPRICE_InsertJournalFromPost]
(
@ResponseID bigint,
@TransactionDetailID bigint
)
AS
BEGIN
DECLARE @info as varchar(max) = '', @Reference as varchar(max) = ''
SET @info = (SELECT SUBSTRING(Response, CHARINDEX('<GlJournal>',Response) + 11,5)
FROM SysproIntegration..ifmTransactionDetailResponse
WHERE TransactionDetailResponseID = @ResponseID)
SET @Reference = (SELECT DISTINCT Reference
FROM GenJournalDetail
WHERE Journal = CAST(@info as DECIMAL(5,0)))
INSERT INTO ZJournalRecords
(JournalNumber,Reference)
VALUES (@info,@Reference)
END
The XML has a tag like this:
<GLJournal>12345</GLJournal>
If the XML document has only one of these tags, I have no worries. The SP works fine. The problem comes in when there are two nested <GLJournal> tags. The xml would then look something like:
<GLJournal>
<SomeTag/>
<SomeTag2/>
<GLJournal>12345</GLJournal>
</GLJournal>
How can I get the 5 digit value of the nested tag? (It will always be 5 digits) I have thought of using a try catch, but that doesn't seem like an elegant solution.
EDIT:
Also, part of the problem is, I don't know when there will be one GlJournal tags, or two.