How can I get the first byte of an integer value in SQL Server?
In C#, I can do it easily using the BitConverter
:
int x = 383;
var firstByte = BitConverter.GetBytes(x)[0];
Console.WriteLine(x);
// Expected Result: 127
How can I get same value in SQL Server query?
Thanks in advance
3条答案
按热度按时间gz5pxeao1#
Ok, I got alternate help from ChatGPT.
But I dont know the theory behind the query.
20jt8wwn2#
If you want the first byte, you can run it through a data type cast. Like so:
If you need to have that as 127 (which in SQL is some sort of numeric data type), cast the result of the binary cast to tinyint (or whatever you want).
cbjzeqam3#