I’m trying to write a Stored Procedure which’ll get a string, hash it with SHA1 and then return the hash. I can’t seem to make it return @hashedString. I’ll admit I’m a total beginner with T-SQL.
I’m writing the T-SQL directly in the db.
This is what I’ve gotten up to now:
ALTER PROCEDURE dbo.ConvertToHash
(
@stringToHash nvarchar(256),
@hashedString nvarchar(256) OUTPUT
)
AS
DECLARE @HashThis nvarchar(256);
SELECT @HashThis = CONVERT(nvarchar(256), @stringToHash);
SELECT @hashedString = HashBytes('SHA1', @HashThis);
Your final select statement is assigning the value rather than returning it. You can either issue another select statement on the relevant variable (modified code included below for your reference) or you can incorporate OUTPUT parameters into your Stored Procedure design, as suggested by Remus.