Hex to ASCII string conversion on the fly

别来无恙 提交于 2021-01-28 17:04:00

问题


I am interested to know if there is a possibility to read the records of a table containing hexadecimal values and convert them on-the-fly into string datatype before displaying / using them as a results (like on the example picture, where the raw data is displayed on the left and how the program interprets it on the right portion).

Data taken from MS Dynamics NAV v5 (SP1) ERP software...

SAMPLE SCREENSHOT

Additionally, I would like to know if there is a possibility of setting a condition (e.g. where) that could be typed as a string (e.g. where something like 'OS%') and DBMS could convert it to hex and search for it in a table to narrow down the end results of a query.

Thank you all in advance for your time.


回答1:


According to your information, that this column is from Microsoft Dynamics NAV it sounds really clear.

The MSDN documentation says this:

Specifies the record that the link is attached to.

The following syntax is used:

<table name>: <primary key1>, <primary key2>, <primary key3>

I'm pretty sure, Microsoft has a combined schema for this value, which is a bit strange but well not that hard to fiddle out I think.

If you split your values up to the FF, you can see two results:

--0xB6A1E6050089FF4252412D4D3032000000
select convert(int,0xB6A1E6050089FF) -- Object_ID for the specified table
select convert(varchar(100),0x4252412D4D3032000000) -- Primary Key 1

You can try to take this further and execute this on your machine:

select object_name(convert(int,0xB6A1E6050089FF))

This should give you a valid table name. Hopefully. ;-)

I can't check this on my side, as I havent those system installed. If so, I can add a short command to this result to automate the splitting for you.

Your other string can be splitted like this:

--0x1E150000008B000000000089FF534F3030303133353532000087102700000000
SELECT convert(int,0x1E150000008B000000000089FF) -- 35327 (object_id)
SELECT convert(varchar(100),0x534F30303031333535320000) -- SO00013552
SELECT convert(int,0x87102700000000) -- 0

I think, you need to parse it dynamically. You should check the basetable (the first part). After that, check the primary keys in their ordering. After checking this, you can dynamically parse them into their target format. The only thing, which may be a bit harder, is the part of the splitting. Normally the first part should go until the FF. After that each part can be splitted by multiple zeros.



来源:https://stackoverflow.com/questions/38295675/hex-to-ascii-string-conversion-on-the-fly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!