I want to sort records by its question no, e.g.: 1 , 2c , 10 , 12a. Is it good to convert them into sum of ascii code? if yes, what would be the error in the following code creating sql funcion? if no, what would be the better way to do that.
CREATE FUNCTION dbo.asciiCodeInteger (@string AS VARCHAR(3))
RETURNS int
AS
BEGIN
DECLARE @result int;
DECLARE @char CHAR(1);
SET @result = 0;
WHILE LEN(@string) > 0
BEGIN
SET @char = LEFT(@string, 1);
SET @result = @result + ASCII(@char);
SET @string = SUBSTRING(@string, 2, LEN(@string));
END
RETURN (@result);
END
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire