SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


PackPrecScale CLR function


PackPrecScale CLR function

Author
Message
cmartel 20772
cmartel 20772
SSC Eights!
SSC Eights! (805 reputation)SSC Eights! (805 reputation)SSC Eights! (805 reputation)SSC Eights! (805 reputation)SSC Eights! (805 reputation)SSC Eights! (805 reputation)SSC Eights! (805 reputation)SSC Eights! (805 reputation)

Group: General Forum Members
Points: 805 Visits: 299
Comments posted to this topic are about the item PackPrecScale CLR function
Solomon Rutzky
Solomon Rutzky
SSChampion
SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)

Group: General Forum Members
Points: 13504 Visits: 3435
Hello Claude. Congrats on publishing your first article on SQL Server Central :-). I think this article is off to a good start, but is incomplete and could use a bit more explanation and examples. For example:

  1. What does "«preemptive» truncation" mean?
  2. What is the output of the initial T-SQL statements? (please see example code below)
  3. What about the rules for precision / scale when it comes to DECIMAL operations? Please see the documentation for "Precision, scale, and Length" (about 1/3 the way down the page).
  4. Why use DECIMAL(38, 18) in the first place?

  5. What do you mean by "culture-independent"? Some of us know, but I suspect many readers won't.
  6. How does one make use of the .NET code shown here? Is it purely a utility for helping with SQLCLR projects? If this is supposed to return a "compacted" T-SQL DECIMAL type, how would you return that from SQLCLR given that the return type (including precision and scale) need to be declared when creating the T-SQL wrapper function? Maybe provide some examples of it being used..
For the initial T-SQL example code in the article that is trying to explain the problem to the reader, you really should show the output of those statements since many readers will not have SSMS open and hence not be able to execute those statements to see what they produce. Below is an example of how to show the output. I also included an additional variable to show the effect of using a properly sized DECIMAL type:

DECLARE @D1 DECIMAL(38, 18) = 1.123456789012345678;
DECLARE @D2 DECIMAL(38, 18) = 1.0;
DECLARE @D3 DECIMAL(1, 0) = 1.0;
DECLARE @D4 DECIMAL(20, 18) = 1.123456789012345678;

SELECT @D1 AS [D1 -- DECIMAL(38, 18)], -- 1.123456789012345678
@D4 AS [D4 -- DECIMAL(20, 18)]; -- 1.123456789012345678

SELECT @D1 * @D2 AS [DEC(38, 18) * DEC(38, 18)], -- 1.123457
@D1 * @D3 AS [DEC(38, 18) * DEC(1, 0)], -- 1.1234567890123457
@D4 * @D2 AS [DEC(20, 18) * DEC(38, 18)]; -- 1.123456789012346


Good luck! Take care, Solomon...

SQL# - https://SQLsharp.com/ ( SQLCLR library of over 340 Functions and Procedures)
Sql Quantum Lift - https://SqlQuantumLift.com/ ( company )
Sql Quantum Leap - https://SqlQuantumLeap.com/ ( blog )
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum









































































































































































SQLServerCentral


Search