Here this script swapping the value of @a and @b variable.
declare @a int
declare @b int
declare @c int
set @a = 123
set @b = 543
print 'Before swapping a : ' + cast(@a as varchar)
print 'Before swapping b : ' + cast(@b as varchar)
set @a = @a + @b
set @b = @a - @b
set @a = @a - @b
print 'After swapping a : ' + cast(@a as varchar)
print 'After swapping b : ' + cast(@b as varchar)
Output will be...
Before swapping a : 123
Before swapping b : 543
After swapping a : 543
After swapping b : 123
No comments:
Post a Comment