August 25, 2006 at 6:40 am
Hi,
I Have Table called Numbers which Contains Columns Num1 and Num2 of same data type. I want a Single Query to swap the rows in the Table. The condition is not to use Temporary Table.
August 25, 2006 at 6:47 am
Swap how? By looking, or permanently? (assume you mean 'swap columns' rather than 'rows')
-- just looking
select num2, num1 from numbers
-- permanent change
update numbers
set num1 = num2,
num2 = num1
/Kenneth
August 25, 2006 at 10:41 am
You can try this
create table Numbers (num1 int,num2 int)
insert into Numbers values(1,2)
insert into Numbers values(3,4)
insert into Numbers values(5,6)
declare @temp int
Update Numbers
set @temp=Num1, Num1=Num2, Num2=@temp
August 26, 2006 at 12:09 am
Yes I got it.Thanks for taking time to reply......
Can we Write a Query to find the Max Number of two given numbers? If so please help me
August 26, 2006 at 3:10 am
I tried the Query I got it.
The Query is
declare @num1 int
declare @num2 int
set @num1 = 1
set @num2 = 1
select (case when @num1 > @num2 then @num1 else @num2 end)
August 26, 2006 at 1:52 pm
Just for grins...
DECLARE @Num1 FLOAT
DECLARE @Num2 FLOAT
SET @Num1 = -1.2
SET @Num2 = -3.4
SELECT Largest = (ABS(Num2-Num1)+(Num2+Num1))/2
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply