3
Answers

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

Methoun Ahmed

Methoun Ahmed

6y
883
1
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)