I am trying to put this Decompress CLR function to work with CROSS APPLY but so far I had not success. The Decompress functions works fine. The problem is开发者_Go百科 to Decompress the column and call .nodes function as shown below. Please, if anyone could help me with that would be great.
SELECT
T0.Chassis.value('Model', 'varchar(50)')
FROM ANYTABLE c
CROSS APPLY CAST( dbo.Decompress( CAST(content AS nvarchar(max)) ) AS xml).nodes('this part is correct') AS T0(Chassis)
You need to split your cast to XML and the .nodes part.
SELECT T0.Chassis.value('Model', 'varchar(50)')
FROM ANYTABLE c
CROSS APPLY (select CAST( dbo.Decompress( CAST(content AS nvarchar(max)) ) AS xml)) as T(X)
CROSS APPLY T.X.nodes('this part is correct') AS T0(Chassis)
Thanks Mikael but I´ve found the answer:
According to the microsoft documentation:
The nodes() function cannot be applied directly to the results of a user-defined function. To use the nodes() function with the result of a scalar user-defined function, you can either assign the result of the user-defined function to a variable or use a derived table to assign a column alias to the user-defined function return value and then use CROSS APPLY to select from the alias.
http://msdn.microsoft.com/en-us/library/ms188282(v=SQL.90).aspx
精彩评论