Nop Checkout Attribute Values in Select Statement

<Attributes>
  <CheckoutAttribute ID="5">
    <CheckoutAttributeValue>
      <Value>TestReward</Value>
    </CheckoutAttributeValue>
  </CheckoutAttribute>
  <CheckoutAttribute ID="1">
    <CheckoutAttributeValue>
      <Value>1</Value>
    </CheckoutAttributeValue>
  </CheckoutAttribute>
</Attributes>

ALTER FUNCTION [dbo].[ecom_get_checkout_attribute_values]
(
    @checkout_attribute_id INT,
    @row_checkout_attributes_xml NVARCHAR(MAX)
)
RETURNS NVARCHAR(MAX)
AS
BEGIN

Declare @_xml as xml;
DECLARE @tbl_checkout_attributes as Table(
Id int,
attribute_value nvarchar(max)
)

SET @_xml = Cast(@row_checkout_attributes_xml as xml)


 INSERT INTO @tbl_checkout_attributes
 Select  nref.value('@ID', 'nvarchar(200)'),nref.value('CheckoutAttributeValue[1]', 'nvarchar(MAX)')
  FROM 
 @_xml.nodes('//Attributes/CheckoutAttribute') AS R(nref)


 RETURN (SELECT attribute_value FRom @tbl_checkout_attributes WHERE id=@checkout_attribute_id)


END




  Select [dbo].[ecom_get_checkout_attribute_values](5,[CheckoutAttributesXml]),* From [Order] where id=36

Comments

Post a Comment