Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

How can you swap values between two rows in a table using single- SQL statement?

Answer Posted / sush4

CREATE TABLE YourTable
(
ID INT,
PlateNo INT,
[Type] VARCHAR(20),
[Image Name] VARCHAR(20)
);

INSERT INTO YourTable
VALUES
(27,455,'User','img1.jpg'),
(32,542,'Alternative','img2.jpg');
SELECT * FROM YourTable

;WITH Cte AS
(SELECT T.*,T2.PlateNo PlateNo2, T2.Type Type2, T2.[Image Name] [Image Name 2] FROM YourTable T JOIN YourTable T2 ON T.ID<>T2.ID)
UPDATE Cte SET PlateNo = PlateNo2, Type=Type2,[Image Name]=[Image Name 2]


SELECT * FROM YourTable

DROP TABLE YourTable

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How sql server executes a statement with nested subqueries?

1020


What is the difference between a view and a stored procedure?

1029


What is the report builder?

139


What is catalog views?

1062


What is 3nf normalization form?

1102


Define full outer join?

945


Define ACID properties in a Database?

1049


What is purpose of normalization?

940


Is it true that rules do not apply to data already existing in a database at the time the rule is created?

1031


Tell me time data type, datetime2, datetimeoffset data type in sql server 2008?

968


How do you check sql server is up and running?

985


Are resultset updatable?

945


What is acid properties?

1083


What is difference between equi join and natural join?

1028


Why use cursor in sql server?

1068