The SQL statement used to query multiple fields, query multiple tables, and delete duplicate records.
SQL repeat record Query
1. Search for redundant duplicate records in the Table. duplicate records are determined based on a single field (peopleId )
Complex. It supports multiple logical operators, including +-and or spaces, and can be added as needed. You can search for the table based on the condition, and the speed is also optimized, which can be said to be very fast. Of course, because it
/*************************************** ***** **************************************** * ******************** Parameter description: 1. tables: Table Name, view 2. primaryKey: Primary keyword 3. sort: Sorting statement without Order By such as
Summary
This article describes varous methods that you canUse to simulate a cursor-like fetch-Next logic in a stored procedure,Trigger, or transact-SQL batch. Use Transact-SQL statements to iterate through a result set
There are three methods you
In ms SQL Server, you can make full use of the stored procedure for page optimization. The following is a good example, which makes full useSet rowcount. During the storage process, you can input the page number of page n to @ startrowindex. @
For example, now there is a person table (table name: peosons)If you want to have the name, ID number, address of these three fields exactly the same records query
Copy Code code as follows:
Select p1.*
From persons p1,persons P2
The simplest net paging program
CREATE procedure [dbo]. [Sp_getpagecontrol](@TableNames nvarchar (200)--table name, can be multiple tables, but cannot be aliased@PrimaryKey nvarchar (100),--primary key, can be null, but @order is empty when the
Commonly used statements
1, look for redundant records in the table, duplicate records are based on a single field (MAIL_ID) to judge
The code is as follows
Copy Code
SELECT * FROM Table WHERE mail_id to (select mail_id
For example:
ID Name Value
1 a pp
2 a PP
3 B III
4 B pp
5 B pp
6 C pp
7 C pp
8 C III
ID is primary key
Ask for such a result
ID Name Value
1 a pp
3 B III
4 B pp
6 C pp
8 C III
Method 1
Delete yourtable
where [id] not in (
Select MAX ([id]) from
One, query a field repeat
Copy Code code as follows:
SELECT *
From User u
where U.user_name in (select U.user_name
From User u
GROUP BY U.user_name has count (*) > 1)
Two, delete the duplicate of a few fields in the
Copy Code code as follows:
Set ANSI_NULLS on
SET QUOTED_IDENTIFIER ON
Go
Create PROCEDURE [dbo]. [Sp_pagination]
/**//*
***************************************************************
* * Tens of millions of levels of paging stored
Note: "Repeat" here is not a complete repetition, meaning a field data duplication
HZT table Structure
ID int
Title nvarchar (50)
Adddate datetime
Data
One. Find duplicate records
1. Find all duplicate records
SELECT * FROM table Where repeat field
CREATE procedure [dbo]. [Protableselectpage](@Tables varchar (1000)--table name such as TestTable@PrimaryKey varchar (100), the primary key of the table, must be unique@Sort varchar = NULL,--sort fields such as f_name ASC or F_name desc (Note that
Method One
Copy Code code as follows:
Declare @max integer, @id integer
Declare cur_rows cursor Local for select main field, COUNT (*) from table name Group by main field having count (*) > 1
Open Cur_rows
Fetch cur_rows into @
Effect Demo: http://www.cn5135.com/_App/Enterprise/QueryResult.aspx
CREATE PROCEDURE cn5135_sp_pagination/***************************************************************** * Tens of millions of levels of paging stored procedures * *******************
Xml
XSLT command [XML format conversion]1. Cycle 2. Sort 3. Conditional processing or or 4. Name Template,,5. Numbering method
XML document [Article.xml] 2897[sharing] Tens of thousands of levels of paging stored procedures (with effect demo)
There are too many files in the machine, so it needs to be sorted out.
This article to organize the picture file for example, give us a little thought
Code's operating environment: Iis5.0+sql server2000
Database scripts:
if exists (SELECT * from
Stored Procedures | Paging in the elite area about stored procedure paging there are probably three ways
respectively:
Temporary tables, see 658037 method to provide a stored procedure paging in the next
cursors, see the 6,580,661 theoretically
asp.net| Pagination | Display Summary: In this paper, we discuss the display of Web database records by using the DataGrid control in the ASP.net framework, and a custom paging display for database records.
Keywords: web database; asp.net;datagrid;
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.