Tasks such as SQL Server simulation data generation and random padding of numeric column values such as Integer, date, and time data types are encountered in the work, and are used to random numbers in these tasks. In view of this, this article
REPLACEReplaces all occurrences of the second given string expression in the first string expression with a third expression.GrammarREPLACE ( ‘string_expression1‘ , ‘string_expression2‘ , ‘string_expression3‘ )Parameters' String_expression1 'The
1.row_number () is the line number2.rank: Similar to Row_number, except that it processes the order by field, and if the field value is the same, the line number remains unchanged3.dense_rank: Similar to rank, the difference is whether the row
In SQL Server database , if the query database has the index of the specified name or foreign key constraints, etc., often use the object_id (' name ', ' type ') method, take notes as follows:?Syntax: object_id (' objectname ') or object ('
Example 1Code to copy code as followsCreate function F_split (@SourceSql varchar (8000), @StrSeprate varchar (10))Returns @temp table (a varchar (100))--function to realize split function--date:2003-10-14AsBeginDECLARE @i intSet @SourceSql =rtrim
In general, the pivot () function can only be written to die in, because pivot () in does not support subqueries, so this can only be solved with stored procedures;CREATE PROCEDURE Insurancepivot@Foldercode VARCHAR (50),@isY VARCHAR (4)AsBEGIN
There is a system table sysobjects in the database, which stores information about each object in the database. Can be queried to see the results. You can see that each object has an ID that stores information about tables, stored procedures,
Write a 1=1 for the following conditions. This SQL should be spelled out in the program, the first thing in the program is not sure whether the following conditions are sure to have, in order to program simple first plus where 1=1, the back can be
I have previously written an article to sort and mentioned the ROW_NUMBER () function. However, many people did not know the detailed usage of this function for the first time.MK is posted here for your reference:Three methods for Mssql to obtain
Example 1 The code is as follows:Copy code Create function f_split (@ SourceSql varchar (8000), @ StrSeprate varchar (10 ))Returns @ temp table (a varchar (100 ))-- Implement the split function-- Date: 2003-10-14AsBeginDeclare @ I intSet @
DateaddReturns a new datetime value based on a specified date.SyntaxDateadd (datepart, number, date)ParametersDatepartIs a parameter that specifies which part of the date should be returned to the new value. The following table lists the date and
If there is such a master-slave table, table 1 represents basic information, and table 2 represents extended information. For example, the master table represents the basic information of purchasers. To simplify the process, all the field names are
Next
4. Conditional SelectionUPDATE.
For example, the following update conditions are available:
For employees with a salary of more than 5000, the salary is reduced by 10%.
Employees with salaries between 2000 and 4600 increase by 15%
You can
Isnull
Replace null with the specified replacement value.Syntax
Isnull(Check_Expression, Replacement_value)Parameters
Check_expression
Whether the expression is null is checked.Check_expressionIt can be of any
SQL Server 2000 provides some XML functions, which are used to convert the XML documents in the component layer of the relational row set through XML, read XML documents, and load data in batches. For example, you can pass an XML document to a
When I read other users' SQL statements today, I still see the decode () function. I have never touched it before. I checked it online. It is quite a useful function, write it down and hope it will help you!
Decode () function
In the use of SQL, we occasionally encounter a situation, that is, the need to change the form of data storage, such as a database of a table (Info) has a field educational (education), previously stored in the JSON array, now because of changes in
Example 1
The code is as follows
Create function F_split (@SourceSql varchar (8000), @StrSeprate varchar)
returns @temp table (a varchar (100))
--function of the split function
--date:2003-10-14
as
begin
Declare @i int
set @SourceSql
The Decode function is a unique method of computing provided by Oracle's SQL software Oracle Pl/sql, known for its concise operations, controllable data models, and flexible format conversions.
Look at other people's SQL today to see that there are
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.