ms sql xml数据类型转换为文本

时间:2011-01-05 15:32:31

标签: sql-server xml delphi text delphi-7

在MS Sql中有delphi 7不支持的数据类型,xml数据类型就是一个例子。

我希望将XML数据类型转换为Text数据类型,以便我可以在delphi中处理它。

有没有办法从xml转换为文本?

3 个答案:

答案 0 :(得分:47)

简单的演员阵容就足够了:

select cast(XMLCol as nvarchar(max)) as XMLCol 

或者对于非unicode:

select cast(XMLCol as varchar(max)) as XMLCol 

您无法明确转换为“文本”数据类型。

我添加了as XMLCol以确保转换后的数据与列名称相同。当然,你不需要这个。

修改

一些链接。我们鼓励您使用nvarchar(max)而不是text。微软已经表示他们将在未来版本中弃用这些类型。 nvarchar(max)应该为你提供2GB:

http://www.petefreitag.com/item/734.cfm

http://www.teratrax.com/articles/varchar_max.html

http://msdn.microsoft.com/en-us/library/ms187752(v=SQL.90).aspx

答案 1 :(得分:10)

SELECT CAST(YourXMLColumn as nvarchar(max))
    FROM YourTable

答案 2 :(得分:0)

我刚刚尝试了以下解决方案,是的,您确实需要SELECT mp.chnl_name AS mp_channel, fsk.sku_prod_id AS pro_id, fsk.dateint AS avlbl_dt, fsk.sku_num AS sku, fsk.upc_txt AS UPC, Coalesce(fsk.brand_name,'N/A') AS brand, fsk.ruckload AS LTL_Flag, fsk.price_amt AS item_selling_price, fsk.on_hand_unit_qty AS qoh, fsk.netpropt AS profite, (fsk.price_amt + fsk.shpg_amt) AS lms, (GP)*100 AS net_pct FROM EDW.ITEM_AVLBL mp JOIN EDW.FULL_SKU fsk ON mp.item_id = fsk.item_id JOIN EDW.SHORT_SKU ssk ON ssk.sh_sku_id = fsk.sh_sku_id WHERE 1=1 AND (mp.chnl_name LIKE '%google%' ---------- This is the prompt value AND fsk.item_create_dt >= '2019-10-20' AND net_pct >= 10 AND (mp.chnl_name <> 'CA_FACEBOOK' -- if not Facebook, don't care ORed terms OR (GP*100 >= 7 AND fsk.first_cost > 500)) GROUP BY 1,2,3,4,5,6,7,8,9,10,11 /* ,fsk.first_cost */

(mp.chnl_name <> 'CA_FACEBOOK' OR mp.chnl_name IS NULL)