Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6220565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:58:45+00:00 2026-05-24T07:58:45+00:00

In my sql server table, I want to add a computed column that is

  • 0

In my sql server table, I want to add a computed column that is a hash of other columns in the same table. Below is my table structure.

Address:
AddressID(int , PK)
AddressLine1 (nvarchar)
AddressLine2 (nvarchar)
City (nvarchar)
State (nvarchar)
AddressHash(computed column)

Below is what I want to get in my computed column:

MASTER.SYS.FN_VARBINTOHEXSUBSTRING(0, HASHBYTES('SHA1',COALESCE(AddressLine1, N'') + COALESCE(AddressLine2, N'') + COALESCE(City, N'') + COALESCE(State, N'')), 1, 0)

If I right-click the table and go to design and enter the above for “Formula” under “Computed Column Specification”, I get the following error:

– Unable to modify table.
A user-defined function name cannot be prefixed with a database name in this context.

So I thought I would use a user defined function to calculate the hash and map that udf to formula.

Below is the code that I am using to create UDF:

CREATE FUNCTION udfHashAddress
(   
    @pAddressLine1 nvarchar(50), @pAddressLine2 nvarchar(50), @pCity nvarchar(50), @pState nvarchar(50))
)
RETURNS nvarchar(max) -- not sure what the correct size would be
WITH SCHEMABINDING
AS
BEGIN   
    DECLARE @result nvarchar(max)   
    SELECT @result = MASTER.SYS.FN_VARBINTOHEXSUBSTRING(0, HASHBYTES('SHA1',COALESCE(@pAddressLine1, N'') + COALESCE(@pAddressLine2, N'') + COALESCE(@pCity, N'') + COALESCE(@pState, N'')), 1, 0)  
    RETURN @result
END
GO

But I get the following error with the above code:

*Cannot schema bind function ‘udfHashAddress’ because name ‘MASTER.SYS.FN_VARBINTOHEXSUBSTRING’ is invalid for schema binding. Names must be in two-part format and an object cannot reference itself.*

When I removed the “MASTER” db prefix I got this error:

*Cannot schema bind function ‘udfHashAddress’ because it references system object ‘SYS.FN_VARBINTOHEXSUBSTRING’.*

Am I missing something here? Would appreciate any assistance/pointers.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T07:58:47+00:00Added an answer on May 24, 2026 at 7:58 am

    Since you’re using SQL Server 2008, have you tried simply:

    CONVERT(VARCHAR(MAX), HASHBYTES('SHA1','string'), 2);
    

    This will return upper case instead of lower case letters, but you can fix that with LOWER() if it’s important.

    Here is an example with your actual schema (created in tempdb on purpose):

    USE tempdb;
    GO
    
    CREATE TABLE dbo.[Address]
    (
        AddressID INT PRIMARY KEY,
        AddressLine1 NVARCHAR(64),
        AddressLine2 NVARCHAR(64),
        City NVARCHAR(64),
        [State] NVARCHAR(64),
        AddressHash AS LOWER(CONVERT(VARCHAR(4000), HASHBYTES('SHA1', 
            COALESCE(AddressLine1, N'') + COALESCE(AddressLine2, N'') 
            + COALESCE(City, N'') + COALESCE([State], N'')), 2))
            --PERSISTED -- you could also persist it if desired
    );
    
    INSERT dbo.[Address]
        VALUES(1, 'foo', 'bar', 'blat', 'splunge'),
              (2, 'bar', 'foo', 'blag', 'splmger');
    
    SELECT *, master.dbo.fn_varbintohexsubstring
        (0,
            HASHBYTES
            (
                'SHA1', 
                COALESCE(AddressLine1, N'') + COALESCE(AddressLine2, N'') 
                + COALESCE(City, N'') + COALESCE([State], N'')
            ), 1, 0)
            FROM dbo.[Address];
    GO
    
    DROP TABLE dbo.[Address];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.