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?



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

Answer / 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

More SQL Server Interview Questions

What is the difference between a function and a trigger?

0 Answers  


What method is used by the Command classes to execute SQL statements that return single values?

0 Answers   B-Ways TecnoSoft,


What is recompile sql server?

0 Answers  


what is maximum size of temp db?

4 Answers   iSoft,


How can windows applications connect to sql servers via odbc?

0 Answers  


What is the Difference Between Primary and Foreign Key?

0 Answers   Accenture, Deloitte, JPMorgan Chase, Maveric,


What do you mean by stored techniques? How would we use it?

0 Answers  


what is bit datatype and what's the information that can be stored inside a bit column? : Sql server database administration

0 Answers  


How to add more data to the testing table in ms sql server?

0 Answers  


Do you know hot add cpu in sql server 2008?

0 Answers  


What is the query and subquery?

0 Answers  


Why functions are used in sql server?

0 Answers  


Categories