<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Getting started with Sql Server 2005 User Defined Types (UDTs)</title><link>http://blogs.msdn.com/angelsb/archive/2004/07/26/197785.aspx</link><description>I have really tried to start with the simplest possible UDT I could come up with. As you can see, the simplest UDT is still quite a handful, and this is still not a complete example. using System; using System.Data.Sql; // Required by SqlUserDefinedType</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>SQL Server 2005 Beta 2 on MSDN</title><link>http://blogs.msdn.com/angelsb/archive/2004/07/26/197785.aspx#197924</link><pubDate>Tue, 27 Jul 2004 10:02:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:197924</guid><dc:creator>MrDave's Blog!</dc:creator><description /></item><item><title>ALTER ASSEMBLY - Take Two</title><link>http://blogs.msdn.com/angelsb/archive/2004/07/26/197785.aspx#200604</link><pubDate>Thu, 29 Jul 2004 15:54:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:200604</guid><dc:creator>Niels SQL Server Blog</dc:creator><description>ALTER ASSEMBLY - Take Two</description></item><item><title>ALTER ASSEMBLY - Take Two</title><link>http://blogs.msdn.com/angelsb/archive/2004/07/26/197785.aspx#200613</link><pubDate>Thu, 29 Jul 2004 16:10:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:200613</guid><dc:creator>Niels SQL Server Blog</dc:creator><description>ALTER ASSEMBLY - Take Two</description></item><item><title>re: Getting started with Sql Server 2005 User Defined Types (UDTs)</title><link>http://blogs.msdn.com/angelsb/archive/2004/07/26/197785.aspx#205919</link><pubDate>Mon, 02 Aug 2004 16:30:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:205919</guid><dc:creator>jasons</dc:creator><description>useless example sorry to say&lt;br&gt;&lt;br&gt;for a start 0,0 is a valid point and so wouldn;t be deemed null i  any natural sense.  also x or y would never be null as they are value types so you should use SqlInt32 or int? (i.e the nullable version).</description></item><item><title>re: Getting started with Sql Server 2005 User Defined Types (UDTs)</title><link>http://blogs.msdn.com/angelsb/archive/2004/07/26/197785.aspx#205939</link><pubDate>Mon, 02 Aug 2004 17:01:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:205939</guid><dc:creator>Angel</dc:creator><description>Jasons,&lt;br&gt;&lt;br&gt;I agree, the example is not particularily usefull in defining a point UDT, it is (as stated) not even a complete example. I am just trying to give an idea of how to get started defining your own User defined Types.&lt;br&gt;&lt;br&gt;That said, why would a null Point udt have to point to x=null, y=null? You can define what a Null Point is in the IsNull property, for example I could decide that a Point with x=100 and y=100 is a Null point. All I need to do is have IsNull return true when x=y=100 and have the static Null return a Point udt with x=y=100.</description></item><item><title>Help...</title><link>http://blogs.msdn.com/angelsb/archive/2004/07/26/197785.aspx#213235</link><pubDate>Thu, 12 Aug 2004 04:33:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:213235</guid><dc:creator>Derrick</dc:creator><description>I tried to create a udt with this code.&lt;br&gt;&lt;br&gt;#region Using directives&lt;br&gt;&lt;br&gt;using System;&lt;br&gt;using System.Data.Sql;&lt;br&gt;using System.Data.SqlTypes;&lt;br&gt;using System.IO;&lt;br&gt;#endregion&lt;br&gt;&lt;br&gt;namespace TypeTest&lt;br&gt;{&lt;br&gt;    [Serializable]&lt;br&gt;    [SqlUserDefinedType(Format.Native, IsByteOrdered = true)]&lt;br&gt;    public struct Point : INullable, IBinarySerialize&lt;br&gt;    {&lt;br&gt;        bool isNull;&lt;br&gt;        private int _X;&lt;br&gt;        private int _Y;&lt;br&gt;        public bool IsNull&lt;br&gt;        {&lt;br&gt;            get{return isNull;}&lt;br&gt;        }&lt;br&gt;&lt;br&gt;        public override string ToString()&lt;br&gt;        {&lt;br&gt;            return X + &amp;quot;:&amp;quot; + Y;&lt;br&gt;        }&lt;br&gt;&lt;br&gt;        public static Point Parse(SqlString s)&lt;br&gt;        {&lt;br&gt;            string[] ls = Convert.ToString(s).Split(char.Parse(&amp;quot;:&amp;quot;));&lt;br&gt;            Point p = new Point();&lt;br&gt;            p.X = Convert.ToInt32(ls[0]);&lt;br&gt;            p.Y = Convert.ToInt32(ls[1]);&lt;br&gt;            return p;&lt;br&gt;        }&lt;br&gt;&lt;br&gt;        public void Read(BinaryReader r)&lt;br&gt;        {&lt;br&gt;            X = r.ReadInt32();&lt;br&gt;            Y = r.ReadInt32();&lt;br&gt;            isNull = BitConverter.ToBoolean(r.ReadBytes(1), 0);&lt;br&gt;        }&lt;br&gt;        public void Write(BinaryWriter w)&lt;br&gt;        {&lt;br&gt;            w.Write(X);&lt;br&gt;            w.Write(Y);&lt;br&gt;            w.Write(isNull);&lt;br&gt;        }&lt;br&gt;&lt;br&gt;        public static Point Null&lt;br&gt;        {&lt;br&gt;            get&lt;br&gt;            {&lt;br&gt;                Point point = new Point();&lt;br&gt;                point.isNull = true;&lt;br&gt;                return point;&lt;br&gt;            }&lt;br&gt;        }&lt;br&gt;&lt;br&gt;        public int X&lt;br&gt;        {&lt;br&gt;            get { return _X; }&lt;br&gt;            set { _X = value; }&lt;br&gt;        }&lt;br&gt;&lt;br&gt;        public int Y&lt;br&gt;        {&lt;br&gt;            get { return _Y; }&lt;br&gt;            set { _Y = value; }&lt;br&gt;        }&lt;br&gt;&lt;br&gt;    }&lt;br&gt;}&lt;br&gt;&lt;br&gt;I'm able to add the assembly to SQL but when I try to create type.&lt;br&gt;&lt;br&gt;CREATE TYPE point external name TypeTest.Point&lt;br&gt;&lt;br&gt;I get.&lt;br&gt;&lt;br&gt;Msg 6556, Level 16, State 1, Line 1&lt;br&gt;CREATE TYPE failed because it could not find type 'Point' in assembly 'TypeTest'.&lt;br&gt;Msg 6597, Level 16, State 1, Line 1&lt;br&gt;CREATE TYPE failed.&lt;br&gt;&lt;br&gt;Can anyone help me with this?</description></item><item><title>re: Getting started with Sql Server 2005 User Defined Types (UDTs)</title><link>http://blogs.msdn.com/angelsb/archive/2004/07/26/197785.aspx#213619</link><pubDate>Thu, 12 Aug 2004 17:22:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:213619</guid><dc:creator>Angel</dc:creator><description>I have a few comments on the UDT itself:&lt;br&gt;&lt;br&gt;You don't need to specify IsByteOrdered for format=Native udt.&lt;br&gt;You don't need to implement IBinarySerialize for format=Native udt. there is nothing wrong with it if you wan't to use this behavior on the client side, but the UDT will not be serialized on the server using your Read and Write methods.&lt;br&gt;&lt;br&gt;IsNull is not going to work the way you expect it to. Once you create a Null UDT no matter what changes you do to it it will continue being IsNull=true, very bad. Instead of returning a property you should have some logic that returns true when this.udt = the udt created when calling Null. In this case when this udt = new Point.&lt;br&gt;&lt;br&gt;The easiest way to properly register your UDT is using Visual Studio 2005 beta. If you don't want to use VS then the syntax for registering a UDT should be in the following format:&lt;br&gt;&lt;br&gt;Register the assembly (you mention you got this working)&lt;br&gt;CREATE ASSEMBLY TypeTest FROM &amp;lt;local drive\TypeTest.dll&amp;gt;&lt;br&gt;CREATE TYPE Point EXTERNAL NAME TypeTest:Point&lt;br&gt;&lt;br&gt;Let me know if this works for you.&lt;br&gt;</description></item></channel></rss>