Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 to get teh next sequence number

Author  Topic 

ibin
Starting Member

26 Posts

Posted - 2009-10-23 : 00:45:08
in a table i have values like this:
BHGK1
BHGK2
BHGK3...

how to get the next sequence number...??i.e BHGK4

sanoj_av
Posting Yak Master

118 Posts

Posted - 2009-10-23 : 00:51:55
Select substring(column_name,1,4) + LTRIM(str(substring(column_name,5,len(column_name))+1))
Go to Top of Page

ibin
Starting Member

26 Posts

Posted - 2009-10-23 : 01:15:20
Thanks..
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-10-23 : 01:22:39
Follow this too

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=134792

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-10-23 : 01:25:03
select left('BHGK2',4)+ cast(right('BHGK2',len('BHGK2')-4)+1 as varchar(3))

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-10-26 : 09:18:36
[code]
DECLARE @refNo VARCHAR(50),
@referencenumber VARCHAR(32)
SELECT @ReferenceNumber = ''

SELECT @ReferenceNumber = MAX(empid)
FROM urtablename

IF ISNULL(@ReferenceNumber,'') = ''
SELECT @refno = 'BHGK'+ '1'
ELSE
SELECT @refno = 'BHGK'+ RIGHT( CAST(CAST(RIGHT(@ReferenceNumber, 4) AS INT) + 1 AS VARCHAR(6)), 6)

SELECT @referencenumber = @refno
SELECT @referencenumber
[/code]
Go to Top of Page
   

- Advertisement -