|
| Previous Thread: CLR Aggregate SqlFacet |
|
|
3/4/2006 5:08:35 PM Set CLR Accumulator Return Type |
Perhaps I'm looking in the wrong place, but I don't see where VS figures out
the type, precision and scale of a CLR Accumulator. The Accumulator compiles
as "[Numeric] (18,0)" which strips off the fractional part of the
value--which is kinda wrong for a money type. Unless the SqlFacet somehow
sets this, I don't know where else to turn.
--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
|
|
|
|
|
3/6/2006 8:26:53 AM Re: Set CLR Accumulator Return Type |
Thanks Kent. I'll try this approach. Is SqlFacet really needed?
--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
"Kent Tegels" <ktegels@develop.com> wrote in message
news:b87ad74135158c80f176ddd3160@news.microsoft.com...
|
|
|
3/6/2006 9:21:19 AM Re: Set CLR Accumulator Return Type |
While this helps define the SqlDecimal precision and scale, it does not set
the Return type for the aggregate. I'm still getting a Numeric(18,0) as the
type. I still think this needs to be set as an Aggregate attribute or a
SqlFacet attribute, but the compiler does not accept SqlFacet anywhere in
the Accumulator-at least not in any of the most obvious places.
--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
"Kent Tegels" <ktegels@develop.com> wrote in message
news:b87ad74135158c80f176ddd3160@news.microsoft.com...
|
|
|
3/6/2006 10:07:20 AM Re: Set CLR Accumulator Return Type |
"William \(Bill\) Vaughn" <billvaRemoveThis@nwlink.com> wrote in
news:eXW1iJUQGHA.1676@TK2MSFTNGP14.phx.gbl:
????. The return type of the Aggregate is decided by the Terminate
method. And to indicate precision, scale, size on the return type of a
method you use (as both Kent and I showed) the SqlFacet like so:
[return: SqlFacet(Precision=18,Scale=4)]
public SqlDecimal Terminate() {
return _Sum;
}
In the example above, the aggregate returns a SqlDecimal. Finally you
can if everything else fails, as I said earlier, always catalogue the
aggregate manually: CREATE AGGREGATE .... BOL has full syntax, otherwise
we have fairly good coverage about it in our book.
Niels
--
**************************************************
* Niels Berglund
* http://staff.develop.com/nielsb
* nielsb@no-spam.develop.com
* "A First Look at SQL Server 2005 for Developers"
* http://www.awprofessional.com/title/0321180593
**************************************************
|
|
|
3/6/2006 11:13:21 AM Re: Set CLR Accumulator Return Type |
Yes, but this does not compile in VB.NET -- does this only work in C#?
<Return: SqlFacet(Precision=18,Scale=4)> _
Public Function Terminate() As SqlDecimal
Return _Sum
End Function
--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
"Niels Berglund" <nielsb@develop.com> wrote in message
news:Xns977EB856ACB63nielsbdevelopcom@207.46.248.16...
|
|
|
3/6/2006 11:18:56 AM Re: Set CLR Accumulator Return Type |
"William \(Bill\) Vaughn" <billvaRemoveThis@nwlink.com> wrote in
news:Ou93JIVQGHA.2816@TK2MSFTNGP15.phx.gbl:
In VB I believe you're assigning property values to attributes by the :=
syntax: <Return: SqlFacet(Precision:=18,Scale:=4)>
Niels
--
**************************************************
* Niels Berglund
* http://staff.develop.com/nielsb
* nielsb@no-spam.develop.com
* "A First Look at SQL Server 2005 for Developers"
* http://www.awprofessional.com/title/0321180593
**************************************************
|
|
|
3/6/2006 11:32:17 AM Re: Set CLR Accumulator Return Type |
Okay, but this does not compile
<Return: SqlFacet(Precision=18,Scale=4)> Public Function Terminate() As
SqlDecimal
Return _Sum
End Function
as it does in C#
[return: SqlFacet(Precision=18,Scale=4)]
public SqlDecimal Terminate() {
return _Sum;
}
--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
"Niels Berglund" <nielsb@develop.com> wrote in message
news:Xns977EC47A96F1Cnielsbdevelopcom@207.46.248.16...
|
|
|
3/6/2006 11:58:26 AM Re: Set CLR Accumulator Return Type |
I got the answer from campus:
Public Function Terminate() As SqlFacet(Precision=18,Scale=4) SqlDecimal
Return _Sum
End Function
--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
"William (Bill) Vaughn" <billvaRemoveThis@nwlink.com> wrote in message
news:eOs6uSVQGHA.2628@TK2MSFTNGP15.phx.gbl...
|
|
|
3/6/2006 3:28:14 PM Re: Set CLR Accumulator Return Type |
Hey Bill,
Does this example help?
using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using System.IO;
[Serializable]
[Microsoft.SqlServer.Server.SqlUserDefinedAggregate(Format.UserDefined,MaxByteSize=16)]
public class NewSum : IBinarySerialize
{
SqlDecimal _Sum;
public void Write(BinaryWriter w) {
w.Write(_Sum.Value);
}
public void Read(BinaryReader r) {
_Sum = new SqlDecimal(r.ReadDecimal());
}
public void Init() {
_Sum = new SqlDecimal(18, 4, true, 0, 0, 0, 0);
}
public void Accumulate([SqlFacet(Precision=18,Scale=4)]SqlDecimal Value)
{
_Sum += Value;
}
public void Merge(NewSum Group) {
_Sum += Group._Sum;
}
[return: SqlFacet(Precision=18,Scale=4)]
public SqlDecimal Terminate() {
return _Sum;
}
}
Thank you,
Kent Tegels
DevelopMentor
http://staff.develop.com/ktegels/
|
|