Question : 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:

ersonalstatistik>PBez>30RPBez>lPersonalstatistik><tblPersonalstatistik>31nalstatistik>sonalstatistik>

The desired output:

c1    c2
30    x
31    x

Unfortunately c1 contains only NULL values. Any hints?
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
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

Answer : Query XML data in TSQL

You are close.  Change this:
ref.value('@ERPBez' , 'varchar(20)') AS c1,
To:
ref.value('ERPBez[1]' , 'varchar(20)') AS c1,
Random Solutions  
 
programming4us programming4us