Home Database Mysql Tutorial sqlserver substring函数使用方法小结

sqlserver substring函数使用方法小结

Jun 07, 2016 pm 05:59 PM
sqlserver substring function

在操作sqlserver时候用到了substring函数,特整理一些实例,需要的朋友可以参考下。

在操作sqlserver时候用到了substring函数
SUBSTRING ( expression, start, length )

参数
expression
字符串、二进制字符串、文本、图像、列或包含列的表达式。请勿使用包含聚合函数的表达式。

start
整数或可以隐式转换为 int 的表达式,指定子字符串的开始位置。

length
整数或可以隐式转换为 int 的表达式,指定子字符串的长度(但是结果并补一个返回length字符长度,要看expression的长度和start的设置!!!!!!!!!!!)。

返回值
如果 expression 是一种支持的字符数据类型,则返回字符数据。如果 expression 是一种支持的二进制数据类型,则返回二进制数据。如果 start = 1,则子字符串从表达式的第一个字符开始

需要补充一句的是,开始start位置的设置,确实如果设置为1,会从第一个字符开始计数,2,3,4....以此类推、

select substring(ziduan,1,6)

将会选择字段的前6个字符,比如说是200908

如果设置为0,

同样的执行select substring(ziduan,0,6)

结果会是20090,如果换成-1

同样执行select substring(ziduan,-1,6)

结果会是2009

同样-2,-3,.................依次类推
下面是网络上的其它一些文章。
substring('98765',-1,3) 结果:9
substring('98765',0,3) 结果:98
substring('98765',1,3) 结果:987
关于函数的这种情况,找了点资料,但是仍不是很明白
SubString($sourceString ,$startingLoc,$length)
$sourceString
资源字符串。

$startingLoc
子字符串在资源字符串中的起点。如果此值为负数或 0,则只返回那些所在位置大于零的字符。如果此值大于 $sourceString 的长度,则返回长度为零的字符串。

$length
[可选] 要检索的字符数。如果没有指定此值,它将返回从 $startingLoc 中指定的位置开始直到字符串末尾的所有字符。

如果此值为负数或 0,则只返回那些所在位置大于零的字符。

入门学习SQL
select substring(convert(varchar,birthdate),5,1) as mon ,* from employees
where substring(convert(varchar,birthdate),5,1)='8'
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the difference between mysql and sqlserver syntax What is the difference between mysql and sqlserver syntax Apr 22, 2024 pm 06:33 PM

The syntax differences between MySQL and SQL Server are mainly reflected in database objects, data types, SQL statements and other aspects. Database object differences include the storage engine and how filegroups are specified, and the creation of indexes and constraints. Data type differences involve differences in numeric types, character types, and date and time types. SQL statement differences are reflected in result set limitations, data insertion, update and delete operations, etc. Other differences include how identity columns, views, and stored procedures are created. Understanding these differences is important to avoid errors when using different database systems.

Tips for dynamically creating new functions in golang functions Tips for dynamically creating new functions in golang functions Apr 25, 2024 pm 02:39 PM

Go language provides two dynamic function creation technologies: closure and reflection. closures allow access to variables within the closure scope, and reflection can create new functions using the FuncOf function. These technologies are useful in customizing HTTP routers, implementing highly customizable systems, and building pluggable components.

Considerations for parameter order in C++ function naming Considerations for parameter order in C++ function naming Apr 24, 2024 pm 04:21 PM

In C++ function naming, it is crucial to consider parameter order to improve readability, reduce errors, and facilitate refactoring. Common parameter order conventions include: action-object, object-action, semantic meaning, and standard library compliance. The optimal order depends on the purpose of the function, parameter types, potential confusion, and language conventions.

Complete collection of excel function formulas Complete collection of excel function formulas May 07, 2024 pm 12:04 PM

1. The SUM function is used to sum the numbers in a column or a group of cells, for example: =SUM(A1:J10). 2. The AVERAGE function is used to calculate the average of the numbers in a column or a group of cells, for example: =AVERAGE(A1:A10). 3. COUNT function, used to count the number of numbers or text in a column or a group of cells, for example: =COUNT(A1:A10) 4. IF function, used to make logical judgments based on specified conditions and return the corresponding result.

How to write efficient and maintainable functions in Java? How to write efficient and maintainable functions in Java? Apr 24, 2024 am 11:33 AM

The key to writing efficient and maintainable Java functions is: keep it simple. Use meaningful naming. Handle special situations. Use appropriate visibility.

Comparison of the advantages and disadvantages of C++ function default parameters and variable parameters Comparison of the advantages and disadvantages of C++ function default parameters and variable parameters Apr 21, 2024 am 10:21 AM

The advantages of default parameters in C++ functions include simplifying calls, enhancing readability, and avoiding errors. The disadvantages are limited flexibility and naming restrictions. Advantages of variadic parameters include unlimited flexibility and dynamic binding. Disadvantages include greater complexity, implicit type conversions, and difficulty in debugging.

Where is the navicat database file? Where is the navicat database file? Apr 23, 2024 am 10:57 AM

The location where the Navicat database configuration files are stored varies by operating system: Windows: The user-specific path is %APPDATA%\PremiumSoft\Navicat\macOS: The user-specific path is ~/Library/Application Support/Navicat\Linux: The user-specific path is ~/ .config/navicat\The configuration file name contains the connection type, such as navicat_mysql.ini. These configuration files store database connection information, query history, and SSH settings.

What is the difference between custom PHP functions and predefined functions? What is the difference between custom PHP functions and predefined functions? Apr 22, 2024 pm 02:21 PM

The difference between custom PHP functions and predefined functions is: Scope: Custom functions are limited to the scope of their definition, while predefined functions are accessible throughout the script. How to define: Custom functions are defined using the function keyword, while predefined functions are defined by the PHP kernel. Parameter passing: Custom functions receive parameters, while predefined functions may not require parameters. Extensibility: Custom functions can be created as needed, while predefined functions are built-in and cannot be modified.

See all articles