2017-11-11 4 views
1

私は:で連結された列を持つすべてのレコードを取得しようとしています。SELECTの列を分割する

SELECT serName FROM tblService WHERE serBqtID=1; 

このようなとしてテーブルに格納されたデータ:私は、クエリでカラムから:extraを除去することによって、結果の下に取得したい

serName    serStatus 
-------    --------- 
catering   Available 
Stage    Available 
Projector   Available 
Segreg:extra  Available 
DJ:extra   Available 

serName    serStatus 
-------    --------- 
Segreg    Available 
DJ     Available 

私はわからないんだけど私は上記の質問をする必要があります。

本当にありがとうございます!

SQL Serverの場合

答えて

1

、あなたはどうなる:

select left(t.serName, charindex(':', t.serName + ':') - 1) as serName, . . . 
from tblService t 
where t.serBqtID = 1 and t.serName like '%:%'; 

あなたが使用して列を見つけることができます。

select t.* 
from tblService t 
where t.serBqtID = 1 and t.serName like '%:%'; 

質問に元のタグを使用すると、substring_index()を使用することができますMySQLの、だった:

select substring_index(t.serName, ':', 1) as serName, . . . 
from tblService t 
where t.serBqtID = 1 and t.serName like '%:%'; 
1

MS-SQL用:

select substring(t.serName,0,charindex(':',t.serName)) as serName, . . . 
from tblService t 
where t.serBqtID = 1 and t.serName like '%:%';