SET TEXTSIZE 0;
SET NOCOUNT ON;
-- Create the variables for the current character string position
-- and for the character string.
DECLARE @position int, @string char(15);
-- Initialize the variables.
SET @position = 1;
SET @string = 'Du monde entier';
WHILE @position <= DATALENGTH(@string)
BEGIN
SELECT ASCII(SUBSTRING(@string, @position, 1)),
CHAR(ASCII(SUBSTRING(@string, @position, 1)))
SET @position = @position + 1
END;
SET NOCOUNT OFF;
GO
I am just experimenting with an idea, i may at some stage need to store those codes in a field 77-121-32-119-111-114-100 but i am not sure yet.
--Safety Check
IF OBJECT_ID('dbo.func_ASCIIEncodeString','FN') IS NOT NULL
BEGIN
DROP FUNCTION dbo.func_ASCIIEncodeString
END
GO
--Create the function
CREATE FUNCTION dbo.func_ASCIIEncodeString (@inputString VARCHAR(15))
RETURNS INT
AS
BEGIN
-- Create the variables for the current character string position
DECLARE @position INT = 1;
DECLARE @ASCIIEncodedValue INT = 0;
-- Initialize the variables.
SET @position = 1;
WHILE @position <= DATALENGTH(@inputString)
BEGIN
--Debug Point
--SELECT ASCII(SUBSTRING(@inputString, @position, 1)) AS ASCIIValue,
-- CHAR(ASCII(SUBSTRING(@inputString, @position, 1))) AS CharacterValue
--Add the ASCII value of the currently read character into the return variable
SELECT @ASCIIEncodedValue += ASCII(SUBSTRING(@inputString, @position, 1));
SET @position = @position + 1;
END
--Finally return to caller
RETURN @ASCIIEncodedValue;
END
use Dictionary
insert into TblWords(AsciiEncode)
selectdbo.func_ASCIIEncodeString(Word)
from TblWords
use Dictionary
UPDATE tblwords
SET AsciiEncode = (
select dbo.func_ASCIIEncodeString(Word)
from TblWords)
UPDATE tblw
SET tblw.AsciiEncode = dbo.func_ASCIIEncodeString(tblw.Word)
FROM dbo.tblWords AS tblw
Open in new window