SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 can you spot the difference
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

esthera
Flowing Fount of Yak Knowledge

1395 Posts

Posted - 02/21/2014 :  04:28:10  Show Profile  Reply with Quote
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

201 Posts

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

Lamprey
Flowing Fount of Yak Knowledge

4614 Posts

Posted - 02/21/2014 :  13:44:36  Show Profile  Reply with Quote
Or specify the string as double-byte:
HASHBYTES( 'md5', N'07-1234-test'), 2))

Edited by - Lamprey on 02/21/2014 13:44:48
Go to Top of Page

esthera
Flowing Fount of Yak Knowledge

1395 Posts

Posted - 02/23/2014 :  02:10:02  Show Profile  Reply with Quote
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

India
52325 Posts

Posted - 02/23/2014 :  03:31:30  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000