PROCEDURES AND FUNCTIONS IN .NET LANGUAGES A method is considered precise if its return value does not depend on any calculations that involve System.Single (FLOAT in SQL) or System.Double (REAL in SQL). A method that meets this criterion should set IsPrecise=true; otherwise, it should be false. The reason for this criterion is that typically the hardware in the processor implements arithmetic calculations involving System.Single or System.Double types. Different processors may produce slightly different results for the same calculations. This is not true for calculations involving SqlDecimalor System.Decimal. The Repeatfunction does not use System.Singleor System.Double, so it is precise. The following code is an example of a method that is not precise. [SqlFunction(IsDeterministic = true, IsPrecise = false)] static public SqlInt32 Add3(SqlInt32 i) { double d = 3.0; return i + (int)d; } Scalar-valued functions may be implemented by methods. They are similar to procedures, but they can return any scalar value or a user- defined type. Scalar-valued functions can be used in queries, computed columns, and indexes. For these indexes to work properly, the method that implements the function must be properly decorated with the Sql FunctionAttributeattribute. Functions that return SqlTypes and some others sometimes must specify some extra information that is specific to the type. For example, a SqlDecimal has a precision and scale associated with it. Although an instance of a SqlDecimal has a MaxPrecision and a MaxScale field, the type definition does not. The SqlFacetAttribute is used to add information about the SQL characteristics of the return value of a function. The SqlFacetAttribute has five properties: IsFixedLength, MaxSize, Precision, Scale, and IsNullable. Methods should use the appropriate properties, as shown in the following example. public SqlDecimal Value() [return: SqlFacet(Precision=9, Scale=12)] { // implementation } The SqlFacetAttribute is meant to be used only for return values. Table 3-6 shows the appropriate properties to use for the various SqlTypes.

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost JSP Web Hosting services

Bookmark the permalink.

Comments are closed.