Click here to Skip to main content
15,899,026 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello!
I am using Microsoft SQL Server 2005
I have a table like this:
SQL
QueueNo
 3B001
 3B002  
 3B003
   .
   .
   .
 3B010

Is there a way to get the last number of the QueueNo?
Something like this:
PHP
QueueNo   No
 3B001    1
 3B002    2
 3B003    3
   .      .
   .      .
   .      .
 3B010    10


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

Something like this:

SELECT QueueNo, CAST(REPLACE(QueueNo, '3B', '') AS INT) AS No FROM #Temp
 
Share this answer
 
Hey Try this.

Select MAX(column Name) from Table_Name
 
Share this answer
 
Comments
charliedev 15-May-14 20:29pm    
yea, but i only need last number
Yash Goyal 16-May-14 3:58am    
Then try the below.

declare @test table
(QueueNo varchar (30))

Insert into @test values ('3B001')
Insert into @test values ('3B002')
Insert into @test values ('3B003')
Insert into @test values ('3B004')
Insert into @test values ('3B005')
Insert into @test values ('3B006')
Insert into @test values ('3B007')
Insert into @test values ('3B008')
Insert into @test values ('3B009')
Insert into @test values ('3B010')

Select * from @test

select Max (Queueno) 'Max Queueno', CAST( RIGHT (Max (Queueno),3)as int) 'Max last number' from @test
Have a look at example:
SQL
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900