How to efficiently load XSL documents which will be used in a CLR SP. I want
to avoid loading it every time the SP is invoked.
Thanks,
ChrisHello ChrisHarrington" charrington-at-activeinterface.com,
> How to efficiently load XSL documents which will be used in a CLR SP.
> I want to avoid loading it every time the SP is invoked.
How about in an table, passing it as a parameter?
Thanks,
Kent Tegels, DevelopMentor
http://staff.develop.com/ktegels/|||Kent,
Thanks for responding. This CLR SP stuff in new to me. Could you elaborate
on your suggestion? Do you mean storing the XSL in an XML column in a table?
Thanks,
Chris
"Kent Tegels" <ktegels@.develop.com> wrote in message
news:b87ad7452758c85c8a7518f6a0@.news.microsoft.com...
> Hello ChrisHarrington" charrington-at-activeinterface.com,
>
> How about in an table, passing it as a parameter?
> --
> Thanks,
> Kent Tegels, DevelopMentor
> http://staff.develop.com/ktegels/
>|||> Thanks for responding. This CLR SP stuff in new to me. Could you
> elaborate on your suggestion? Do you mean storing the XSL in an XML column
in a
> table?
I'll post an example in my blog shortly.
Thanks,
Kent Tegels, DevelopMentor
http://staff.develop.com/ktegels/|||Thanks - that would be very helpful.
Chris
"Kent Tegels" <ktegels@.develop.com> wrote in message
news:b87ad7454618c85ce91388c3f0@.news.microsoft.com...
> in a
> I'll post an example in my blog shortly.
>
> --
> Thanks,
> Kent Tegels, DevelopMentor
> http://staff.develop.com/ktegels/
>|||Hello Chris,
Been a bit too busy to post, but here's the gist of it. First, we need a
SQLCLR function that actually does the transformation. Here's that:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using System.Xml;
using System.Xml.Xsl;
using System.IO;
namespace DM.Examples
{
public partial class XmlLibrary
{
[SqlFunction(DataAccess = DataAccessKind.None, IsDeterministic =
false, IsPrecise = false, SystemDataAccess = SystemDataAccessKind.None)]
[return: SqlFacet(IsFixedLength = false, IsNullable = true, MaxSize
= -1)]
public static SqlXml ApplyTransform(SqlXml Data, SqlXml StyleSheet)
{
// on null return null, just in case.
if (Data.IsNull || StyleSheet.IsNull)
return SqlXml.Null;
// Buffer the transformed xml
MemoryStream ms = new MemoryStream();
XmlWriter xw = XmlWriter.Create(ms);
// Load and transform
XslCompiledTransform ctx = new XslCompiledTransform(false);
ctx.Load(StyleSheet.CreateReader());
ctx.Transform(Data.CreateReader(), xw);
// return the result, assuming XML compliant output
return new SqlXml(ms);
}
}
}
here's some code I wrote to test that:
declare @.d xml, @.s xml
select @.d = (select productID as '@.dbid',ProductNumber as '@.productID',Name
as 'name',Color as 'color',ListPrice as 'listPrice',Size as 'Size',SizeUnitM
easureCode
as 'sizeCode',style as 'style' from adventureworks.production.product where
not(coalesce(discontinuedDate,'2999-12-31') = 1) and FinishedGoodsFlag =
1 for xml path('product'),root('products'),element
s xsinil,type)
select @.s = bulkcolumn from openrowset(bulk 'c:\simple.xslt',single_clob)
as p
select dbo.ApplyTransform(@.d,@.s)
the "c:\simple.xlst" is left as an excercise for the reader.
Cheers,
Kent Tegels, DevelopMentor
http://staff.develop.com/ktegels/|||Hi Kent,
Thanks for the code sample. But what I am really stumped on is how to have
the xsl available as a class static so that it doesn't have to be loaded and
compiled every time the SP is invoked. Any thoughts?
Chris
"Kent Tegels" <ktegels@.develop.com> wrote in message
news:b87ad745b3b8c85df2965c9c40@.news.microsoft.com...
> Hello Chris,
> Been a bit too busy to post, but here's the gist of it. First, we need a
> SQLCLR function that actually does the transformation. Here's that:
> using System;
> using System.Data;
> using System.Data.SqlClient;
> using System.Data.SqlTypes;
> using Microsoft.SqlServer.Server;
> using System.Xml;
> using System.Xml.Xsl;
> using System.IO;
> namespace DM.Examples
> {
> public partial class XmlLibrary
> {
> [SqlFunction(DataAccess = DataAccessKind.None, IsDeterministic =
> false, IsPrecise = false, SystemDataAccess = SystemDataAccessKind.None)]
> [return: SqlFacet(IsFixedLength = false, IsNullable = true, MaxSize
> = -1)]
> public static SqlXml ApplyTransform(SqlXml Data, SqlXml StyleSheet)
> {
> // on null return null, just in case.
> if (Data.IsNull || StyleSheet.IsNull)
> return SqlXml.Null;
> // Buffer the transformed xml
> MemoryStream ms = new MemoryStream();
> XmlWriter xw = XmlWriter.Create(ms);
> // Load and transform
> XslCompiledTransform ctx = new XslCompiledTransform(false);
> ctx.Load(StyleSheet.CreateReader());
> ctx.Transform(Data.CreateReader(), xw);
> // return the result, assuming XML compliant output
> return new SqlXml(ms);
> }
> }
> }
> here's some code I wrote to test that:
> declare @.d xml, @.s xml
> select @.d = (select productID as '@.dbid',ProductNumber as
> '@.productID',Name as 'name',Color as 'color',ListPrice as 'listPrice',Size
> as 'Size',SizeUnitMeasureCode as 'sizeCode',style as 'style' from
> adventureworks.production.product where
> not(coalesce(discontinuedDate,'2999-12-31') = 1) and FinishedGoodsFlag = 1
> for xml path('product'),root('products'),element
s xsinil,type)
> select @.s = bulkcolumn from openrowset(bulk 'c:\simple.xslt',single_clob)
> as p
> select dbo.ApplyTransform(@.d,@.s)
> the "c:\simple.xlst" is left as an excercise for the reader.
> Cheers,
> Kent Tegels, DevelopMentor
> http://staff.develop.com/ktegels/
>
Showing posts with label loading. Show all posts
Showing posts with label loading. Show all posts
Thursday, March 8, 2012
Sunday, February 12, 2012
beginner - case sensitive query
Hi
We are taking case sensitive data, and loading it into an Access 2000 database using an OBDC. We then use VB 6 to produce an SQL .exe file which manipulates the data into new tables for the CR.
We have a a select statement where we have
SELECT ....
INTO A_POS
FROM POS LEFT JOIN CHTAB ON POS.STATUS = CHTAB.STATUS
The trouble is the client has the codes "F" and "f" in the CHTAB.STATUS, so I am producing duplicate A_POS records for any POS record with a status of "F".
Any suggestions as to how I can check the case sensitivity in Access so I create clean tables?
Thanks.
_Do you want to make all "f" to "F"?
Post some sample data and the result you want|||Unfortuneately, we are a software house, so we can't go and demand our clients change the codes. One client had all their company structure codes in upper case, and when they changed the company structure, they kept all the same codes, but changed them to lower case. Thus on the database "MELB" and "melb" could appear in one historic view, and have totally different properties.
I have an Organisation chart file ORG, which is keyed by the field OFFICE. I also have an employee positions file, POS. One of its attributes is OFFICE. Both "MELB" and "melb" are valid, but distinct, office codes.
My select statment is:-
select ... from POS LEFT JOIN ORG WHERE POS.OFFICE = ORG.OFFICE
And I need to somehow tell the script that I want the matching to be case sensitive, so I only pick up the correct upper (or lower) case office, not both.
Thanks
We are taking case sensitive data, and loading it into an Access 2000 database using an OBDC. We then use VB 6 to produce an SQL .exe file which manipulates the data into new tables for the CR.
We have a a select statement where we have
SELECT ....
INTO A_POS
FROM POS LEFT JOIN CHTAB ON POS.STATUS = CHTAB.STATUS
The trouble is the client has the codes "F" and "f" in the CHTAB.STATUS, so I am producing duplicate A_POS records for any POS record with a status of "F".
Any suggestions as to how I can check the case sensitivity in Access so I create clean tables?
Thanks.
_Do you want to make all "f" to "F"?
Post some sample data and the result you want|||Unfortuneately, we are a software house, so we can't go and demand our clients change the codes. One client had all their company structure codes in upper case, and when they changed the company structure, they kept all the same codes, but changed them to lower case. Thus on the database "MELB" and "melb" could appear in one historic view, and have totally different properties.
I have an Organisation chart file ORG, which is keyed by the field OFFICE. I also have an employee positions file, POS. One of its attributes is OFFICE. Both "MELB" and "melb" are valid, but distinct, office codes.
My select statment is:-
select ... from POS LEFT JOIN ORG WHERE POS.OFFICE = ORG.OFFICE
And I need to somehow tell the script that I want the matching to be case sensitive, so I only pick up the correct upper (or lower) case office, not both.
Thanks
Subscribe to:
Posts (Atom)