Methoun Ahmed

Methoun Ahmed

  • NA
  • 145
  • 101.9k

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

Answers (3)