How i can get the first 3 digits in 123456 Numbers

2019-04-25 04:59发布

I have field called CallingParty in My CDR table it contains data like this

CallingParty

267672668788

I want to select the first 3 number of each of those numbers like

CallingParty

267

5条回答
走好不送
2楼-- · 2019-04-25 05:21

if CallingParty is of type int:

SELECT CAST(LEFT(CallingParty, 3) AS INT)
From CDR
查看更多
女痞
3楼-- · 2019-04-25 05:24

Try this:

SELECT Substring(callingparty, 1, Length(callingparty) - 9) 
FROM   cdr; 
查看更多
迷人小祖宗
4楼-- · 2019-04-25 05:27

Use this query:

SELECT SUBSTRING(CAST(CallingParty AS VARCHAR(50)), 1, 3) FROM [CDR]
查看更多
ら.Afraid
5楼-- · 2019-04-25 05:43

SQL Server has a Left() function, but it works best on strings. (varchar/char in SQL)

Select left(cast(267672668788 as varchar), 3)
查看更多
来,给爷笑一个
6楼-- · 2019-04-25 05:43

If the data length does not change then you can always divide by 10 * the digits you have

SELECT FLOOR(267672668788 / 1000000000)
=267
查看更多
登录 后发表回答