May 31, 2007 at 11:45 am
Hi. As a new sysadmin, I've inherited a system built on SQL Server 2000, with a VB6 frontend. I have no formal experience with SQL, but you know how it is I need a password to the system, but the field which stores passwords in the users table is varbinary. I was trying a query to reset the admin password:
update dbo.tblusers set password ='whatever' where userid = '1'
and I get:
"Disallowed implicit conversion from data type varchar to data type varbinary, table 'Investments.dbo.tblUsers', column 'PassWord'. Use the CONVERT function to run this query."
I've researched the CONVERT function, but I don't understand the syntax. I'm thinking I could also try an insert statement to create a new user. Could anyone offer some guidance?
Thanks.
June 1, 2007 at 6:09 am
here's an example I keep around for casting from nvarchar to varbinary and then back to nvarchar:
the key is to use nvarchars... i beleive this fails if you try to use plain old varchar.
DECLARE @var VARBINARY(128),
@res NVARCHAR(64)
SET @var = CAST(N'Hello World' AS VARBINARY(128))
PRINT @var
--results: 0x480065006C006C006F00200057006F0072006C006400
SET @res = CAST(@var AS NVARCHAR(64))
PRINT @res
--results: Hello World
--The same but using CONVERT:
SET @var = CONVERT(VARBINARY(128), (N'Bananas and Oranges'))
PRINT @var
--results: 0x420061006E0061006E0061007300200061006E00640020004F00720061006E00670065007300
SET @res = CONVERT(NVARCHAR(64),@var)
PRINT @res
--results: Bananas and Oranges
[edited]
forgot to say, so in your example, you would change your statement to be this:
update dbo.tblusers set password =CAST(N'whatever' AS VARBINARY(128)) where userid = '1'
Lowell
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy