I want to store the value of userId as " XYZ" but when after executing the below code got output as "XYZ".
Want to store the value with leading space.
Declare @xml Nvarchar(100),
@hDoc Int,
@user Nvarchar(30)
SET @XML= '<ROOT><DETAIL ID ="1" name ="ABC" userId=" XYZ" /></ROOT>'
EXEC sp_xml_preparedocument @hDoc OUTPUT, @xml
SELECT @user = userId
FROM OPENXML(@hDoc, '/ROOT/DETAIL')
WITH ( userId Nvarchar(30) )
EXEC sp_xml_removedocument @hDoc
SELECT @user