July 22, 2018 at 2:13 am
Comments posted to this topic are about the item Variable assignments
July 22, 2018 at 2:14 am
Good question, thanks Evgeny
...
July 22, 2018 at 7:25 am
Clever! Hopefully both values aren't more than 50% of the max for the given datatype.
--Jeff Moden
Change is inevitable... Change for the better is not.
July 22, 2018 at 11:02 pm
Brilliant..
Nice one to start the week on, thanks Evgeny
July 22, 2018 at 11:03 pm
Great question.
Nice trick.
____________________________________________
Space, the final frontier? not any more...
All limits henceforth are self-imposed.
βlibera tute vulgaris exβ
July 23, 2018 at 1:52 am
I got it right, but I was a bit confused by the word "swaping"! I thought: "Is that anything to do with 'vaping'?". Then I realised the question was referring to "swapping".
You never know: reading my book: "All about your computer" might just tell you something you never knew!
lulu.com/kaspencer
July 23, 2018 at 5:02 am
nice question, cheers
---------------------------------------------------------------------------------------
The more you know, the more you know that you dont know
July 23, 2018 at 7:50 am
I actually had to think about that one for a minute. Nice.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
July 23, 2018 at 10:20 am
Keep in mind that this trick relies on behavior that is not only undocumented but officially undefined. There is no guarantee that this trick will work with the next SQL Server update.
Selecting multiple values into variables is also not ANSI standard but I'm less concerned about that.
July 23, 2018 at 1:46 pm
lmalatesta - Monday, July 23, 2018 10:20 AMKeep in mind that this trick relies on behavior that is not only undocumented but officially undefined. There is no guarantee that this trick will work with the next SQL Server update.Selecting multiple values into variables is also not ANSI standard but I'm less concerned about that.
Heh... While what you say is true, I'll take the bet that it'll work with the next SQL Server update... and the next several dozen after that. π
The major concern that I have with this trick is that if @a and @b-2 are each more than 50% (or some other combination) of the maximum for the given datatype, then @a+@B will cause a failure. It would be much safer (and perhaps quicker because there's no math involved) to use the 3 variable method for doing such a swap.
--Jeff Moden
Change is inevitable... Change for the better is not.
July 24, 2018 at 12:01 am
Lordy, I love this community!. Thanks Mike. Makes perfect sense. A group of Exclusive Or gates in hardware is sometimes referred to as an "adder" but with a "wrap around". Works the same way in software if the software is written correctly. Nicely done.
--Jeff Moden
Change is inevitable... Change for the better is not.
July 24, 2018 at 5:26 am
This is an example of the XOR swap algorithm:
https://en.wikipedia.org/wiki/XOR_swap_algorithm
July 24, 2018 at 6:25 am
Jeff Moden - Tuesday, July 24, 2018 12:01 AMLordy, I love this community!. Thanks Mike. Makes perfect sense. A group of Exclusive Or gates in hardware is sometimes referred to as an "adder" but with a "wrap around". Works the same way in software if the software is written correctly. Nicely done.
Meh! Write a CLR to do a simple switch just for audacity π :laugh:
Far away is close at hand in the images of elsewhere.
Anon.
July 24, 2018 at 8:44 am
David Burrows - Tuesday, July 24, 2018 6:25 AMJeff Moden - Tuesday, July 24, 2018 12:01 AMLordy, I love this community!. Thanks Mike. Makes perfect sense. A group of Exclusive Or gates in hardware is sometimes referred to as an "adder" but with a "wrap around". Works the same way in software if the software is written correctly. Nicely done.
Meh! Write a CLR to do a simple switch just for audacity π :laugh:
Heh... too funny. That reminds me that I wrote an enterprise wide disk checker that uses T-SQL to build a bit of dynamic PowerShell that calls WMI that gets executed through xp_CmdShell.and the results are parsed by persisted computed columns on the table that I direct the xp_CmdShell output to and then HTML format the output using T-SQL and send it using CDOSys (instead of sp_send_dbmail) just to piss off a couple of pro-PowerShell/anti-xp_CmdShell/"just because you can" zealots. It works fine but the PowerShell slows it down a fair bit and this reminded me that I need to fix it to just use xp_CmdShell and WMI. It'll greatly simplify the code and improve the performance, as well π
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 15 posts - 1 through 15 (of 18 total)
You must be logged in to reply to this topic. Login to reply