Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 can you spot the difference

Author  Topic 

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2014-02-21 : 04:28:10
what is the difference between the 2 selects below that they give me different results?


declare @p nvarchar(30)
select @p='07-1234-test'
select upper(CONVERT(VARCHAR(MAX), HASHBYTES( 'md5',@p), 2))
select upper(CONVERT(VARCHAR(MAX), HASHBYTES( 'md5','07-1234-test'), 2))

wided
Posting Yak Master

218 Posts

Posted - 2014-02-21 : 05:58:55
to have same result:
declare @p varchar(30) not nvarchar(30)
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2014-02-21 : 13:44:36
Or specify the string as double-byte:
HASHBYTES( 'md5', N'07-1234-test'), 2))
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2014-02-23 : 02:10:02
thanks but i'm trying to understand that

why does varchar work and not nvarchar
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-02-23 : 03:31:30
quote:
Originally posted by esthera

thanks but i'm trying to understand that

why does varchar work and not nvarchar


Nvarchar is unicode data type so it will store unicode equivalent and requires double the space

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -