当前位置: 动力学知识库 > 问答 > 编程问答 >

sql - How do you select specific data from a column returned by a simple select statement?

问题描述:

I have run a select statement in sql and the data has returned in the specific column as for example

Select reference from referencetable

JOEDOW12345678111111

What I require is to select DOW12345678 from the column. The field is always going to be 20 characters long. It will always begin with JOE and end with 111111 so basically I just need to return the 11 characters after JOE which will always be 11 long. This is a reference that is all I require

So when doing a select how do I just select specific data from that column. In my case the reference which is in the middle of the data returned by the select statement.

Any help would be greatly appreciated

Thanks

网友答案:

Since it is going to be specific length you can directly use substring method. Fetching 11 chars from 4th should do what you want. This is how it would be done in MySQL:

select substr(reference, 4, 11) from referencetable;
网友答案:

The function to use depends on the database:

MySQL, Oracle, Postgresql

select substr(reference,4,11) from referencetable

Microsoft SQL Server

select substring(reference,4,11) from referencetable

Microsoft Access

select mid(reference,4,11) from referencetable
分享给朋友:
您可能感兴趣的文章:
随机阅读: