LoginSignup
0
0

More than 1 year has passed since last update.

SQL 文字列切り出し

Posted at

SQL Serverを使って、文字列の先頭から何文字を切り出したい。

LEFT関数を使う。

LEFT(文字列, 文字数)

例えば、

SELECT name, LEFT(name, 3) from students;

Sato が Satになったり、先頭から3文字切り取られます。
1.PNG

SQL Serverには、他にもRIGHT関数があり、こちらは、右から切り取りを行います。

SELECT name, RIGHT(name, 3) from students;

2.PNG

SUBSTRINGもあります。SUBSTRING(文字列, スタート位置, 文字数) 。

Select name, SUBSTRING(name, 2, 2) from students;

3.PNG

参考ページ

https://www.fenet.jp/dotnet/column/database/sql-server/5257/
https://sql55.com/t-sql/sql-server-built-in-string-function-1.php

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0