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 2005 Forums
 Transact-SQL (2005)
 the data type varchar and varchar are incompatible

Author  Topic 

sql_newb2043
Starting Member

2 Posts

Posted - 2012-04-24 : 03:15:20
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

3271 Posts

Posted - 2012-04-24 : 03:53:50
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/
Go to Top of Page

sql_newb2043
Starting Member

2 Posts

Posted - 2012-04-24 : 04:03:05
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

3271 Posts

Posted - 2012-04-24 : 04:47:21
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

52326 Posts

Posted - 2012-04-24 : 21:51:58
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
   

- Advertisement -