Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Right Shift And Left Shift Operator in SQL Server

In SQL Server, shift operators are not present as per knowledge.

If I have to achieve right shift and left shift, what will be the efficient way of doing it?

  1. With mathematical expressions which will give me the same output as shift operator must have given.

OR

  1. Will call CLR function to calculate the right shift and left shift because shift operators are available in C# which will give me the output what I am expecting.

Please suggest which one will be the more efficient way of doing it.

like image 581
Liquid Avatar asked Oct 16 '25 03:10

Liquid


1 Answers

From SQL Server 2022 you can simply use

  • LEFT_SHIFT ( expression_value, shift_amount ) (or <<)
  • RIGHT_SHIFT ( expression_value, shift_amount ) (or >>)
like image 68
Martin Smith Avatar answered Oct 18 '25 20:10

Martin Smith



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!