Discover sql server scalar function example, include the articles, news, trends, analysis and practical advice about sql server scalar function example on alibabacloud.com
entered in the numeric expression Rand returns the random float value between 0 and 1 round returns the numeric expression and rounding to the specified length or precision sign returns the positive (+ 1) of the given expression), zero (0) or negative (-1) Signs sin returns the given angle (in radians) in an approximate number (float) expression) Square returns the square of the given expression SQRT returns the square root of the given expression tan returns the tangent of the input exp
Recent time from the client to the background to write services, for the background database and service writing is a small white, so the recent written certainly not too much technical content.
First put the problems encountered: or that error on the report, the main fields have reported error ID (ErrorID), reported (Reportperson), escalation time (reporttime) accurate to milliseconds, now to do the statistics are: (1) Statistics for a certain period of time " From start to end time is accurat
+name from Car; The query here will display the code and name two varchar type Lian as a string concatenation.Similarly, if it is a column of two value types, it will follow the mathematical operationConvert (type, column name) type conversionCast (column name as type)Time-Date functionGETDATE () Gets the current timeYear (GETDATE ()) Gets the years in the current timeMonth (GETDATE ()) Gets the months in the current timeDAT (GETDATE ()) DayIsDate (time date) determines whether the time date is
-- Simple Case FunctionCASE sexWHEN '1' THEN 'male'WHEN '2' THEN 'female'ELSE 'others' END-- Case search functionCase when sex = '1' THEN 'male'WHEN sex = '2' THEN 'female'ELSE 'others' END
These two methods can achieve the same function. Simple Case functions are relatively simple in writing, but compared with Case search functions, there are some functional limitations, such as writing Case functions.Note that the Case
-- Simple Case FunctionCASE sexWHEN '1' THEN 'male'WHEN '2' THEN 'female'ELSE 'others' END-- Case search functionCase when sex = '1' THEN 'male'WHEN sex = '2' THEN 'female'ELSE 'others' END
These two methods can achieve the same function. Simple Case functions are relatively simple in writing, but compared with Case search functions, there are some functional limitations, such as writing Case functions.Note that the Case
CREATE TABLE student (ID VARCHAR2 (5) Primary key,name VARCHAR2 (+), not null,sex char (2) Check (sex= ' male ' or sex= ' female ')--to Stude NT inserts a piece of data, using a function to verify that the insert is correct create or replace function (f_id in Varchar2,f_name in Varchar2,sex in varchar2) return VARCHAR2 isc_ ID number;beginif f_id is null thenreturn (' number cannot be empty, record is not s
--sql Regular Replace function
The Code is as follows: CREATE function Dbo.regexreplace ( @source ntext, the original string @regexp varchar (1000),--Regular expression @rep Lace varchar (1000),--Replaces the value @globalReplace bit = 1, whether it is global replace @ignoreCase bit = 0-Ignore case ) ReturnS varcha R (1000) as begin Declare @hr integ
Use sum (SUM) FunctionThe sum function is used to return the sum of all values in the expression. This function is usually used to summarize some data.
Syntax:
Sum ([All | distinct] expression)
Parameter description:
L all: Performs aggregate function operations on all values. All is the default setting.
L distinct: Specify sum to return the sum of unique values.
Tags: font and interval Lower OLE lua ber boolean value simhttps://docs.microsoft.com/en-us/sql/t-sql/functions/rand-transact-sql?view=sql-server-2017Generate random numbers within a certain intervalHttps://stackoverflow.com/questions/7878287/generate-random-int-value-from-3
If you want to remember the records in a table for random display, or randomly extract a record, we do not need to write a long stringProgramCodeHow can we create a random number and then make a so-called "random record"? You only need to use a small function in SQL Server to implement the random sorting or random extraction
SQL Server Stored Procedure/function encryption/Decryption
Encryption of stored procedures and stored functions: With Encryption
Create procedure DBO. sp_xml_main
@ Table_name nvarchar (260) = '',
@ Dirname nvarchar (20) =''
With Encryption
As
Begin
....................
End
Go
Decryption of stored procedures and stored Functions
If exists (select * From DBO. syso
The SQL statement waitfor can be written to a stored procedure and executed again: waitfor {delay 'time' | time' time} the time after delay is the delay time after which the execution time is specified. The format is "HH: mm: SS ", the following is an example of a date not supported: ------ specify to execute beginwaitfor time '10: 00' select * From tablenameend ----- specify to wait for 1 hour and then exe
SQL SERVER ranking function RANK, DENSE_RANK, NTILE, ROW_NUMBERPrefaceThis document describes how to use instance data to help you understand SQL SERVER ranking functions RANK, DENSE_RANK, NTILE, and ROW_NUMBER.PreparationsCreate a test table:
create table test(id int ident
or higher, charindex returns NULL. If the database compatibility level is 65 or lower, charindex returns NULL only when both expression1 and expression2 are null.If expression1 cannot be found in expression2, charindex returns 0.
Problems encountered during actual use:The cursor is used in the above trigger, but in the above usage, when charindex (@ temp1, @ temp2) is used, both parameters are variable (trigger or stored procedure) in the program) it will not be executed. If you do not know the
Measure_heat Show Results: The results are rather ugly and clear, we can use the graphical visualization of the way to view, the display is more intuitive. 4. There are also set functions related to performance analysis, such as SET STATISTICS XML --XML format output query plan
SETSTATISTICS profile on -- Each query that executes returns its regular result set For example, when profile is set to ON, the result is much like set SHOWPLAN_ALL on, w
SqlServer2005 above provides window sorting and window aggregation functions.Sort by rank () and row_number () two function window.The rank () function is arranged identically to produce the same sort, and the next different sort will be skipped, such as generating 1, 1, 3.The Row_number () function produces a different sort, such as a-to-do, even if arranged ide
Tags: reserved sel turn Select End--Locate UML ConvertSometimes you need to reserve a specified number of digits for a specific number that contains a decimal point, such as "123.123600". This is implemented as a function in the database as follows: Use [Database name]
GO
/** * * * object:userdefinedfunction [dbo]. [Avglimit] Script DATE:2016/12/29 11:30:44 * * * * **/
SETAnsi_nulls on
GO
SETQuoted_identifier on
GO
Create
Encryption of stored procedures and stored functions: With Encryption
Create procedure DBO. sp_xml_main
@ Table_name nvarchar (260) = '',
@ Dirname nvarchar (20) =''
With Encryption
As
Begin
....................
End
Go
Decryption of stored procedures and stored functions (this is a stored procedure)If exists (select * From DBO. sysobjects where id = object_id (n' [DBO]. [sp_decrypt] ') and objectproperty (ID, n' isprocedure') = 1)Drop procedure [DBO]. [sp_decrypt]Go/* -- Crack functions, proces
Whether int or varchar is used, it is hard to cope with multiple Status queries. For example, in general thinking, The Enum settings for CustomerStatus are as follows:
Copy codeThe Code is as follows: [Serializable]
Public enum CustomerStatus
{
New = 0,
Active = 1,
Overdue = 2,
Sushortded = 3,
Closing = 4,
Closed = 5
}
The Status value is stored in the database as an int.What should I do if I want to search for a Customer in the Active, Overdue, and s
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.