MSDN有一個很好的例子。我將其修改爲採用之前的ASCII值來反轉您的數據庫,然後將其返回。
if object_id('tempdb..#psswd') is not null drop table #psswd
create table #psswd (userid int, pswd varchar(40))
insert into #psswd (userid, pswd) values (1,'pnfe'), (2,'tofuujl')
DECLARE @userID int = 2
-- Create variables for the character string and for the current
-- position in the string.
DECLARE @position int
-- Initialize the current position and the string variables.
SET @position = 1;
WHILE @position <= DATALENGTH((SELECT pswd FROM #psswd WHERE userid = @userID))
BEGIN
SELECT CHAR(ASCII(SUBSTRING(REVERSE(pswd), @position, 1)) - 1) FROM #psswd WHERE userid = @userID
SET @position = @position + 1
END;
GO
Credit
如果你正在嘗試對數據進行加密,您可以使用可用的加密其他優雅的方式在SQL Server –
哦......哦,我的..這很可能會成爲純文本密碼。主要沒有沒有。 – Kritner
密碼應該永遠是單向的!不應該解密;您的前端必須處理這一問題,通過回答一些安全問題讓用戶自行重置密碼 – techspider