• Toll-free  888-665-8637
  • International  +1 717-220-0012
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Steve95
#1 Posted : Thursday, August 13, 2015 6:19:34 AM(UTC)
Steve95

Rank: Member

Joined: 4/29/2010(UTC)
Posts: 253

Thanks: 4 times
Was thanked: 11 time(s) in 10 post(s)
As per the title, I need to get the Shiping Address Country BVIN from the bvc_Orders.Shipping address field for an Audit report but I am having trouble as the database column is nText and not xml.

Does anyone know how to retrive the value using sql only as it need to be presented to Crystal Reports.

Many thanks
Steve95
#2 Posted : Thursday, August 13, 2015 9:01:09 AM(UTC)
Steve95

Rank: Member

Joined: 4/29/2010(UTC)
Posts: 253

Thanks: 4 times
Was thanked: 11 time(s) in 10 post(s)
Just incase anyone else needs to do this, the following sql will find all orders with a status of complete between 1st of July and the 31st July 2015. It will return the CountryBvin and CountryName from the Shipping field in bvc_Order along with the Order Number and Order bvin

With
CTE AS (
SELECT o.[Bvin], o.[OrderNumber], cast (o.[ShippingAddress] AS xml) As XML, o.GrandTotal FROM [dbo].[bvc_Order] o
where o.[IsPlaced] = 1
and o.[TimeOfOrder] > '2015-06-30 23:59:59'
and o.[TimeOfOrder] <= '2015-07-31 23:59:59'
and o.StatusCode = '09D7305D-BD95-48d2-A025-16ADC827582A'
)
SELECT [Bvin], [OrderNumber], Shipping.addr.value('CountryBvin[1]','varchar(36)') as ShippingCountryBvin, Shipping.addr.value('CountryName[1]','nvarchar(max)') as ShippingCountryName
FROM CTE
CROSS APPLY xml.nodes('Address') Shipping(addr)
Order by [OrderNumber] asc

Edited by user Thursday, August 13, 2015 9:03:36 AM(UTC)  | Reason: typo

Aaron
#3 Posted : Thursday, August 13, 2015 11:02:32 AM(UTC)
Aaron

Rank: Administration

Joined: 4/2/2004(UTC)
Posts: 2,381
United States
Location: Hummelstown, PA

Thanks: 6 times
Was thanked: 163 time(s) in 158 post(s)
Yep, casting the column as XML and using XPath is the answer. At some point we will convert these columns to XML. The reason that that were originally created as ntext was for backward compatibility with old versions of SQL Server.
Aaron Sherrick
BV Commerce
Toll-free 888-665-8637 - Int'l +1 717-220-0012
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

©2024 Develisys. All rights reserved.
  • Toll-free  888-665-8637
  • International  +1 717-220-0012