Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

SQL Server

1 réponse
Avatar
berthome
Bonjour,

J ai une table qui reçois des données binaires dans une colonne rdr_RawData.
Je dois parser la chaine afin d'en extraire différentes informations :

J'extrait 0x1003CE114F03931E91001E0CD907081A0C0000001E000000000000000000
de cette colonne.


substring( [rdr_RawData], 3 , 4 ) me renvois 0x034F11CE
CAST(substring( [rdr_RawData], 3 , 4 ) as INT) renvois -837726461



REVERSE(substring( [rdr_RawData], 3 , 4 )) as varbinary(4)) renvois
0xCE114F03
CAST(CAST(REVERSE(substring( [rdr_RawData], 3 , 4 )) as varbinary(4)) AS
INT) renvois 55513550


Bien sur c'est la seconde interpretation qui m'interesse (55513550).

Y a t il un meilleur moyen d'y arriver?
- choisir le type d'interpretation des données binaires pour un cast ou
un convert.
- par un function CLR

Fabien Berthomé

1 réponse

Avatar
Med Bouchenafa
Cela a l'air de faire ce que tu veux
Sinon, tu peux t'amuser avec les fonctions sys.fn_varbintohexstr et
sys.fn_varbintohexsubstring
Mais bon cela ne fait rien de plus que ce tu as deja fait
Tu pourrais rendre ton code plus elegant en ecrivant tes propres fonctions

En 2008, il ya aussi un nouveau truc qui permet de convertir directement du
BINARY EN CHAR et vice versa

SELECT CAST ([rdr_RawData] AS VARCHAR (4)) AS BIN_TO_CHAR_NO_PREFIX;

Bien cordialement
Med Bouchenafa

"berthome" wrote in message
news:#
Bonjour,

J ai une table qui reçois des données binaires dans une colonne
rdr_RawData.
Je dois parser la chaine afin d'en extraire différentes informations :

J'extrait 0x1003CE114F03931E91001E0CD907081A0C0000001E000000000000000000
de cette colonne.


substring( [rdr_RawData], 3 , 4 ) me renvois 0x034F11CE
CAST(substring( [rdr_RawData], 3 , 4 ) as INT) renvois -837726461



REVERSE(substring( [rdr_RawData], 3 , 4 )) as varbinary(4)) renvois
0xCE114F03
CAST(CAST(REVERSE(substring( [rdr_RawData], 3 , 4 )) as varbinary(4)) AS
INT) renvois 55513550


Bien sur c'est la seconde interpretation qui m'interesse (55513550).

Y a t il un meilleur moyen d'y arriver?
- choisir le type d'interpretation des données binaires pour un cast ou un
convert.
- par un function CLR

Fabien Berthomé