1. 程式人生 > >SQL Server中擷取字串常用函式

SQL Server中擷取字串常用函式

SQL Server 中擷取字串常用的函式:

1.LEFT ( character_expression , integer_expression )
函式說明:LEFT ( '源字串' , '要擷取最左邊的字元數'  )
返回從字串左邊開始指定個數的字元
select LEFT('SQL_Server_2008',4 );
返回結果:SQL_


2.RIGHT ( character_expression , integer_expression )
函式說明:RIGHT ( '源字串' , '要擷取最右邊的字元數'  )
返回字串中從右邊開始指定個數的 integer_expression 字元
select RIGHT('SQL_Server_2008',4 );
返回結果:2008


3.SUBSTRING ( character_expression , start , length )
函式說明:SUBSTRING ( '源字串' , '擷取起始位置(含該位置上的字元)' , '擷取長度' )
返回字元、binary、text 或 image 表示式的一部分
select SUBSTRING('SQL_Server_2008',5 ,6);
返回結果:Server