server| function
Two uses of functions in SQL Server (which can be used in place of cursors)
1. Because the update can not use stored procedures, but to update the table based on some of the fields to be calculated. We often use the method of the cursor, which is implemented using the method of the function.
Function section:
The following is a reference fragment:CREATE FUNCTION [DBO]. [Fun_gettime] (@TASKPHASEID INT)RETURNS FLOAT asBEGINDECLARE @TASK
1. First talk about the difference between pl/SQL and SQL * plus. For example, it is easy to understand:
Pl/SQL-> C ++ LanguageSQL * plus-> Microsoft Visual C ++ 6.0 Compiler
Pl/SQL is the language of oracle extended SQL. It includes standard
Label:We do software development, most people are inseparable from dealing with the database, especially the development of ERP, and database dealing with more frequent, storage process is thousands of rows, if the volume of data large, people flow, then I can also guarantee the next period of time the system can still run smoothly? So can the next person be able to understand my stored procedures? Then I combined with the company's usual training and personal work experience and share with you,
Chinese reprinted --
Add SQL Server statements and stored procedures to favorites-- ===================================================== ====================-- List all SQL Server tables, field names, primary keys, types, lengths, decimal places, and other information-- Run the query analyzer to generate a table and export it to excel.-- ======================================
Everything is for performance, everything is for businessFirst, the logical execution order of the query(1) from left_table (3) Join_type join Right_table (2) in Join_condition (4) WHERE where_condition (5) GROUP by group_by_list (6) with {cube | rollup} (7) has having_condition (8) SELECT (9) DISTINCT (one) top_specification select_list (9) ORDER by Order_by_listThe parsing order of standard SQL is:(1) The FROM clause assembles data from different da
After a DML statement is executed, the results of the DML statement are stored in four cursor attributes, which are used to control the program flow or understand the program status. When running DML statements, PL
After a DML statement is executed, the results of the DML statement are stored in four cursor attributes, which are used to control the program flow or understand the program status. When running DML statements, PL/
SQL % found,
TBGroup BY name--sql SERVER 2000 Dynamic SQL, refers to the course of more than language, mathematics, physics, this course. (hereinafter)DECLARE @sql varchar (8000)Set @sql = ' Select Name 'Select @sql = @sql + ', max (case cour
Reprint Address: http://blog.csdn.net/dba_huangzj/article/details/8300784#Directory
First look at the brief definition of Books Online
Grammar
Here are a few more useful examples
First take a look at how this function is used on MSDN COALESCE function returns a value that is not NULL in a parameter, such as
Then take a look at applying the function to pivot. The following statement runs on the AdventureWorks database
If you want to reverse the result you
Statement
Real-Life SQL statement collection (constantly updated-)
Foreword: Here will I encounter the programming practice of the value of the SQL statement down the road, on the one hand to facilitate their own search, on the other hand, also tamping the memory of the impending forgotten. Throughout the process I will keep on updating until I can no longer add, and at the same time, only record the most
ALTER PROCEDURE _tmp@id varchar (a), @PN varchar, @Type intasbegin/**********************************--Features: Multi-conditional query performance _tmp ' K3g8kg6nn94sbbs0 ', ' k7f7ff ', 0************************** ********/PRINT 'number of test data bars 500W' Set NOCOUNT ondeclare @time datetimedeclare @Warring VARCHAR (@Type =1 OR @Type =0) beginset @Warring =char (10) + 'the first way, the direct spelling of SQL statements, there is a
related table, which requires us to write the SQL When you try to make the optimizer use the index. In order for the optimizer to use the index efficiently, it should be noted when writing statements: (1123456789A, do not operate on the indexed fields, but want to do a change, such asSELECT ID from T WHERE num/2=100should read:SELECT ID from T WHERE num=100*2 SELECT ID FROM T WHERE NUM/2=NUM1
如果NUM有索引应改为:
SELECT ID FROM T WHERE NUM=NUM1*2
如果NUM1有索引则不
, which is not only a Chinese, a mathematical, or an English subject. (Same as below)Declare @ SQL varchar (8000)Set @ SQL = 'select sname'Select @ SQL = @ SQL + ', max (case subject when ''' + Subject + ''' then scores else 0 end) [' + Subject + ']'From (select distinct subject from TB) asSet @
SQL Tune Report-sqltrpt. SQL, reportsqltrpt. SQL
ORACLE 10 Gb provides a script sqltrpt. SQL to query the most resource-consuming SQL statements. The output result is divided into two parts:
15 Most expensive SQL in the cursor cac
. Therefore, the column alias in the select clause is not recognized in the WHERE clause.
3. Example
Business: to query the list of purchase orders, you must display the master information of the order and the total number of purchases for each order;
Test data:
The following SQL statements cannot be searched:
SelectSo. order_no ,(Select Sum(SOD. good_num)From [Stockorderdetails] AsSODWhereSOD. order_id=So. ID)AsOrder_numFrom [Stockorder] AsS
The following SQL paragraph, what do you think the result is?DECLARE @A VARCHAR (SET @a= ' zuowenjun.cn ' SELECT TOP 1 @a=isnull (FIELDNAME, ' DEFAULT ') from TABLENAME WHERE 1=2print @AGOIt may be thought that the result is:default, because the variable @a initialized to: zuowenjun.cn, after executing the SQL query, because the condition 1=2 is not established,
T-SQL is an enhanced SQL language provided by SQLServer based on the SQL language. The T-SQL provides all the features of ANSISQL and adds more features such as extended functions, system pre-storage, and program design structures. The following describes
3. the T-SQL of
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.