[英]Retrieve xml-data from text-column
I've a table which has a field (datatype "text") that contains a xml-file.我有一个表,其中有一个包含 xml 文件的字段(数据类型“文本”)。 After some try and error I found out that the only way to fetch the complete xml-file from that table is to use the "FOR XML" clause of ms sql. But my next problem is, that the colum containing the xml-file is named something like "XML_F52E2B61-18A1-11D1-B105-00805F49916B" which is an invald identifier for cf.
经过一些尝试和错误后,我发现从该表中获取完整 xml 文件的唯一方法是使用 ms sql 的“FOR XML”子句。但我的下一个问题是,包含 xml 文件的列是命名为“XML_F52E2B61-18A1-11D1-B105-00805F49916B”之类的东西,这是 cf 的无效标识符。
Is there a way to access that column by its id instead of its name or what's the best way to access this column?有没有办法通过它的 id 而不是它的名称来访问该列,或者访问该列的最佳方法是什么?
Edit: The SQL statement I'm using is:编辑:我使用的 SQL 语句是:
SELECT XmlPackage
FROM LogK3OnChange
WHERE DealerID = IsNull(<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.dealerid#">, DealerID)
AND LogID = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.logid#">
FOR XML RAW
Regards,问候,
Heiko平子
If you embed your query in a sub-query you can give your column a name.如果将查询嵌入到子查询中,则可以为列命名。
select
(
select *
from YourTable
for xml path('Row'), root('Root')
) as NewColumnName
With your query:随着您的查询:
SELECT
(
SELECT XmlPackage
FROM LogK3OnChange
WHERE DealerID = IsNull(<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.dealerid#">, DealerID)
AND LogID = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.logid#">
FOR XML PATH
) AS NewColumnName
Update:更新:
If you want the column to be a XML data type you should add the type
keyword to your query.如果您希望该列是 XML 数据类型,您应该将
type
关键字添加到您的查询中。 Not sure if that would make a difference for coldfusion.不确定这是否会对 coldfusion 产生影响。
SELECT
(
SELECT XmlPackage
FROM LogK3OnChange
WHERE DealerID = IsNull(<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.dealerid#">, DealerID)
AND LogID = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.logid#">
FOR XML PATH, TYPE
) AS NewColumnName
Got it知道了
<cfoutput>#myQuery["XML_F52E2B61-18A1-11D1-B105-00805F49916B"][1]#</cfoutput>
does the trick做的伎俩
This is a better answer as it does not rely on a string that may potentially change in some later revision of coldfusion.这是一个更好的答案,因为它不依赖于可能在 coldfusion 的某些后续版本中发生变化的字符串。
<cfoutput>#QueryName[QueryName.ColumnList][1]#</cfoutput>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.