I got little question. I want to generate auto customernumber, with Surname as startpoint. I take first two chars from surname and convert them to ascii.
But my function returns the varchar as 147 when it should be 7869.
so the function sums 78 + 69. So the question is, how do i paste 78 + 69 together in a varchar.
But my function returns the varchar as 147 when it should be 7869.
so the function sums 78 + 69. So the question is, how do i paste 78 + 69 together in a varchar.
Code:
USE [SoevereinCRM] GO /****** Object: UserDefinedFunction [dbo].[F_Create_KlantNummer] Script Date: 10/31/2007 16:12:04 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: Wouter Neuteboom -- Create date: 31-10-2007 -- Description: KlantNummer creëren -- ============================================= ALTER FUNCTION [dbo].[F_Create_KlantNummer] ( @Achternaam nvarchar(50) ) RETURNS nvarchar(6) AS BEGIN DECLARE @KlantNummer nvarchar(6) DECLARE @string nvarchar(2) DECLARE @position int DECLARE @integer int SET @string = UPPER(SUBSTRING(@Achternaam, 1, 2)) SET @position = 1 SET @KlantNummer = '000000' WHILE @position <= 2 BEGIN SET @integer = (SELECT ASCII(SUBSTRING(@string, @position, 1))) SET @KlantNummer = @KlantNummer + @integer SET @position = @position + 1 END RETURN @KlantNummer END
Comment