Methoun Ahmed

Methoun Ahmed

  • 1.8k
  • 145
  • 44.6k

Conversion failed when converting the varchar value 'S-01'

Sep 10 2018 11:08 AM
Here is my code
 
Create function [dbo].[CASNo]()
returns varchar(20)
as
begin
DECLARE @lastval INT
SET @lastval = (select MAX(Cast(right(CAS_No,4) as varchar(10))) from tblCASdetails)
if @lastval is null set @lastval = 0
Return 'CAS-' + right('000' + convert(varchar(50),(@lastval + 1)),10)

end

Brought to you by:

Answers (3)