Alibabacloud.com offers a wide variety of articles about sql server if then else example, easily find your sql server if then else example information here online.
//Error statement: There is a syntax error near the keyword ' user '; - //user is the keyword in the SQL statement, if you want to use user as the table name, you must enclose the user in square brackets [], that is [user]; to + //processing result sets (including metadata); - //Print property name; theResultSetMetaData Rsmetadata =Resultset.getmetadata (); * for(inti = 1; I ) { $System.out.printf ("%
However, before SQL server 2005, SQL SERVER 2000 did not provide this direct function for us to use. The same is true for ACCESS.
The following describes the implementation process of data ranking in two cases. The test data is as follows:
The result after ranking is as follows:
AccessCopy codeThe Code is as follo
Stored procedure (procedure. SQL ):Create procedure hello@ Yourname varchar (50) = "no name"AsSelect @ yourname + ", Hello! "GoPHP3 program (procedure. php3 ):$ Server = mssql_connect ("localhost", "sa", "") or die ("unable to connect to the database server! ");$ Db = mssql_select_db ("test", $
Data operations between databases */
-- Create a linked server
Exec sp_addrole server 'itsv', '', 'sqloledb', 'remote server name or IP address'
Exec sp_add1_srvlogin 'itsv', 'false', null, 'username', 'Password'
-- Query exampleSelect * From itsv. Database Name. DBO. Table Name
-- Import exampleSelect * into table from itsv. Database Name. DBO. Table Name
-- De
Algorithm is an important research direction in computer science, and it is the key to solve complex problems. In the computer world, algorithms are everywhere. The database is the place that stores the data and executes the large quantity computation, in the database uses some simple SQL commands, carries on the storage, the inquiry, the statistics, solves the real world problem already is not uncommon. With the increase of data volume and the increa
, because it will delete the things that others have added.(Assume that a single user can delete a product with comments, but not just comments)Then, after modifying the document, the operator implies several changes:1. Added some products2. modified some items3. Some items have been deleted.
One direct SQL implementation:
-- Update if it exists. If it does not exist, insert it.If exists (select 1 from morder with (nolock) Where morderid = @ ID and PK
1, the column to change careersAfter the data is calculated and processed, the data source needed for the front-end chart is generated directly, but the program needs to write the data into the middle table, and query the data directly from the middle table the next time the data is queried.1.1-Column line wrapping syntaxTable_sourceUnpivot (Value_columnFor Pivot_columnIn ()1.2 Row column CaseWith TAs(SELECT 1 as Teamid, ' Test team 1 ' as team,80 ' MEN ', ' WOMEN 'UNIONSELECT 2 as Teamid, ' Tes
Classes;Update classes Set name = ' Five class ' WHERE name = ' Class 5 ';The update trigger saves the updated data in the deleted table after the data is updated, and the updated data is saved in the inserted table. # Update column-level triggers if (object_id (' Tgr_classes_update_column ', ' TR ') is not null)Drop Trigger Tgr_classes_update_columnGoCreate Trigger Tgr_classes_update_columnOn classesFor updateAs--Column-level triggers: Whether the class creation time has been updatedif (updat
Now you need to query a set of data, which is the grouping of data in a column of fields (COLUMN01) after a range of queries:Select (Casewhen [Column01] >0 and [column01] Example of use in SQL Server to determine grouping sorting
.[id]When matchedThen update set T.[DESC]=S.[DESC]When not matchedThen insert values (S.[id],s.[desc])When not matched by sourceThen deleteOutput $action as[ACTION],Inserted. [ID] as Insertid,Inserted. [Desc] as Inserddesc,Deleted. [ID] as Deleteid,Deleted. [Desc] as Deletedesc;----Join a conditionMerge into targettable as TUsing SourceTable as S on T.[id]=s.[id]When matched and s.[id]=3Then update set T.[DESC]=S.[DESC]When not matchedThen insert values (S.[id],s.[desc])When not matched by sourc
It mainly uses case statements to solve the problem of Row-to-column conversion.
The row-to-column conversion problem is mainly divided into two types:
1) Simple row-to-column conversion:
Example Table:
Id Sid Course Result
1 2005001 Chinese 80.02 2005001 mathematics 90.03 2005001 English 80.04 2005002 Chinese 56.02005002 mathematics 69.06 2005002 English 89.0
Run
Select Sid, language = isnull (sum (Case course when 'China' then resul
drop table [a] go create table [a] ([ID] int) insert [a] select 1 union allselect 1 union allselect 2 union allselect 3 union allselect null select * from a/* (5 rows affected) ID-----------1123NULL (5 rows affected) */--> test data: [B] if object_id ('[B]') is not null drop table [B] go create table [B] ([ID] int) insert [B] select 1 union allselect 2 union allselect 2 union allselect 4 union allselect null select * from B/* (5 rows affected) ID-----------1224NULL (5 rows affected) */-- merge
I did one of those things before, move the file to D on all databases (except SQL Server system files) that were originally on C, for easy follow-up management and reduced disk I/O blocking (c, D is 2 standalone disks). Script needs to enter 2 parameters: Target database name and target directory nbsp; Code as follows: Use master go nbsp; DECLARE nbsp; nbsp; @DBName sysname, nbsp; nbsp; @DestPath varchar (
Being familiar with the use of SQL Server wildcard characters in some situations can help us solve a lot of problems simply.
--Use the _ operator to find the three-letter name at the end of the person table
USEAdventureWorks2012;
Go
SELECT FirstName, LastName from
person.person
WHERE FirstName like ' _an ' order by
FirstName;
---Use the [^] operator to find all names in the Contact table that star
However, before SQL server 2005, SQL SERVER 2000 did not provide this direct function for us to use. The same is true for ACCESS.
The following describes the implementation process of data ranking in two cases. The test data is as follows:
The result after ranking is as follows:
Access
Copy codeThe Code is as f
SQL Server, use exec to handle a variable in the SQL string, hint: The scalar variable must be declared @ (resolved!) )
Copy Code code as follows:
declare @tssj nvarchar (100)--External variables
declare @Sql_Sql nvarchar (100)--Save SQL string variable
Set @Sql_Sql =n ' select @tssj =jpk from b where bzm
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.