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
 SQL Server Administration (2005)
 Converting NVARCHAR to DEC

Author  Topic 

lrennells1
Starting Member

1 Post

Posted - 2009-03-27 : 11:43:34
Help--

I have a SQL 2005 DB that has a table called ItemAssociation. The table has a column named RFIDNumber that is a 24 characters and stored as a nvarchar. The first 16 characters are the same as this is a unique RFID value assigned to my company. The last 8 characters are actually a hex value. I need to convert the last 8 characters from hex to dec to obtain the 8 digit RFIDNumber.

A sample RFIDNumber is 34180B0A00000000013154B8.

Here is my query:

select
top 100
ia.Code,
ia.RFIDNumber as RFIDFullHexNumber,
right(ia.RFIDNumber,8) as Last8HexNumber,

convert(nvarchar,right(ia.RFIDNumber,8)),
convert(int,convert(nvarchar,'0x'+right(ia.RFIDNumber,8))) as RFIDNumber,

ia.SerialNumber,
ia.Manufacturer,
ia.Model,
ia.Grid,
a.StatusName,
rtrim(ltrim(left(l.LocationName,13))) as MailCode,
rtrim(ltrim(substring(l.LocationName,16,len(l.LocationName)))) as RoomName,
---ia.LocationCode,
ia.ModifiedBy,
ia.LastModifiedDate

from dbo.ItemAssociation ia
inner join dbo.AssetStatus a
on ia.AssetStatusCode = a.Code
inner join dbo.Location l
on ia.LocationCode = l.Code

The problem is when I run the query I get the following errort: Conversion failed when converting the nvarchar value '0x013154B8' to data type int.

Any help would be greatly appreciated. I don't want to convert the column in the database, just convert the output results.

Luke
luke@lukester.net

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-03-27 : 12:00:36
Check this link...

http://blogs.msdn.com/rextang/archive/2008/01/13/7091118.aspx

you can use this UDF for your conversion

Go to Top of Page
   

- Advertisement -