获取代码的最后一个数字(SQL) [英] Get last number of a code (SQL)

查看:89
本文介绍了获取代码的最后一个数字(SQL)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!

我正在使用Microsoft SQL Server 2005

我有一个这样的表:

 QueueNo 
3B001
3B002
3B003



3B010



有没有办法获得最后一个QueueNo号?

这样的东西:

<前lang =PHP> QueueNo否
3B001 1
3B002 2
3B003 3
。 。
。 。
。 。
3B010 10





真的需要弄清楚这一个。

提前致谢! :)

解决方案

这样的事情:



 SELECT QueueNo,CAST( REPLACE(QueueNo,'3B','')AS INT)AS No FROM #Temp 


嘿试试这个。



从Table_Name中选择MAX(列名)


看看例子:

  SELECT 代码, CONVERT  INT 正确(代码, 3 )) AS  CodeNo 
FROM
SELECT ' 3B010' AS 代码
UNION ALL
SELECT ' 3B001' AS 代码
AS T







退货:

 3B010 10 
3B001 1


Hello!
I am using Microsoft SQL Server 2005
I have a table like this:

QueueNo
 3B001
 3B002  
 3B003
   .
   .
   .
 3B010


Is there a way to get the last number of the QueueNo?
Something like this:

QueueNo   No
 3B001    1
 3B002    2
 3B003    3
   .      .
   .      .
   .      .
 3B010    10



Really need to figure this one out.
Thanks in advance! :)

解决方案

Something like this:

SELECT QueueNo, CAST(REPLACE(QueueNo, '3B', '') AS INT) AS No FROM #Temp


Hey Try this.

Select MAX(column Name) from Table_Name


Have a look at example:

SELECT Code, CONVERT(INT,Right(Code,3)) AS CodeNo
FROM (
    SELECT '3B010' AS Code
    UNION ALL
    SELECT '3B001' AS Code
) AS T




Returns:

3B010	10
3B001	1


这篇关于获取代码的最后一个数字(SQL)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆