Stephan_Schrandt
asked on
Query XML data in TSQL
Hello,
I'm trying to access an xml parameter as rows in TSQL. The proc is in code section. The parameter value I pass is:
<dsPersonalstatistik><tblP ersonalsta tistik><ER PBez>30</E RPBez></tb lPersonals tatistik>< tblPersona lstatistik ><ERPBez>3 1</ERPBez> </tblPerso nalstatist ik></dsPer sonalstati stik>
The desired output:
c1 c2
30 x
31 x
Unfortunately c1 contains only NULL values. Any hints?
I'm trying to access an xml parameter as rows in TSQL. The proc is in code section. The parameter value I pass is:
<dsPersonalstatistik><tblP
The desired output:
c1 c2
30 x
31 x
Unfortunately c1 contains only NULL values. Any hints?
ALTER PROCEDURE sp_Import__Personaldata (
@Content xml
/*@LastChangeUserID uniqueIdentifier,
@MandantID uniqueIdentifier */
)
AS
BEGIN
SET NOCOUNT ON
DECLARE @ErrMSG nvarchar(1000)
BEGIN TRY
BEGIN TRANSACTION
BEGIN
SELECT
ref.value('@ERPBez' , 'varchar(20)') AS c1,
'x' as c2
FROM @Content.nodes('//dsPersonalstatistik/tblPersonalstatistik') AS R(ref)
END
COMMIT
END TRY
BEGIN CATCH
SET @ErrMSG = Error_Message()
raiserror(@ErrMSG,16,1)
ROLLBACK TRANSACTION
RETURN
END CATCH
END
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you, working perfectly.
Open in new window