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 2005 Forums
 Transact-SQL (2005)
 the data type varchar and varchar are incompatible
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sql_newb2043
Starting Member

2 Posts

Posted - 04/24/2012 :  03:15:20  Show Profile  Reply with Quote
I am getting this error, the data type varchar and varchar are incompatible in the boolean XOR operator, what am I doing wrong? Below is my query. i am actually doing XOR on two strings. Is this format is correct?

firstly I updated the password, converted in hex and save it.
UPDATE tbl_user SET password = SubString(master.dbo.fn_varbintohexstr(HashBytes('MD5', 'admin123')), 3, 32) WHERE login_id = 'user123'

The above is working fine, but below is not working fine, giving the error "the data type varchar and varchar are incompatible in the boolean XOR operator".

DECLARE @var1 varchar(42), @var2 varchar(32), @var3 varchar(32)
SET @var1 = 'The universe is made of stories not atoms.'
SELECT @var2 = password FROM tbl_user WHERE login_id = 'user123'
SET @var3 = CONVERT(varchar(42), @var1) ^ CONVERT(varchar(32), @var2)
SELECT @var3

Lumbago
Norsk Yak Master

Norway
3241 Posts

Posted - 04/24/2012 :  03:53:50  Show Profile  Reply with Quote
From BOL:
quote:
^ (Bitwise Exclusive OR) (Transact-SQL)
Performs a bitwise exclusive OR operation between two integer values.


- Lumbago
My blog-> http://thefirstsql.com/2011/07/08/how-to-find-gaps-in-identity-columns-at-the-speed-of-light/

Edited by - Lumbago on 04/24/2012 03:54:53
Go to Top of Page

sql_newb2043
Starting Member

2 Posts

Posted - 04/24/2012 :  04:03:05  Show Profile  Reply with Quote
what I have done now

DECLARE @var1 varchar(42), @var2 varchar(32), @var3 varchar(32)
SET @var1 = 'The universe is made of stories not atoms.'
SELECT @var2 = password
FROM emp_user
WHERE login_id = 'mobile'
SET @var3 = CAST(@var1 AS INT) ^ CAST(@var2 AS INT)
SELECT @var3

now it is giving an error Conversion failed when converting the varchar value '' to data type int
Go to Top of Page

Lumbago
Norsk Yak Master

Norway
3241 Posts

Posted - 04/24/2012 :  04:47:21  Show Profile  Reply with Quote
How on earth are you going to convert the string 'The universe is made of stories not atoms.' to a number??? You will have to make sure that the string you are converting is in fact convertable BEFORE you do the actual conversion. You can use the ISNUMERIC function for example...

- Lumbago
My blog-> http://thefirstsql.com/2011/07/08/how-to-find-gaps-in-identity-columns-at-the-speed-of-light/
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47037 Posts

Posted - 04/24/2012 :  21:51:58  Show Profile  Reply with Quote
quote:
Originally posted by sql_newb2043

what I have done now

DECLARE @var1 varchar(42), @var2 varchar(32), @var3 varchar(32)
SET @var1 = 'The universe is made of stories not atoms.'
SELECT @var2 = password
FROM emp_user
WHERE login_id = 'mobile'
SET @var3 = CAST(@var1 AS INT) ^ CAST(@var2 AS INT)
SELECT @var3

now it is giving an error Conversion failed when converting the varchar value '' to data type int


what is the int value you need to convert '' to?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

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.42 seconds. Powered By: Snitz Forums 2000