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 are the grouping functions?

0 Answers  


OPTIMIZATION OF SP,CURSOR,TRIGGERS

0 Answers  


What are the different types of backups avaialabe in sql server 2005?

0 Answers  


Describe how to use linked server?

0 Answers  


what are the different ways of moving data/databases between servers and databases in sql server? : Sql server database administration

0 Answers  


How you can get a list of all the table constraints in a database? : Sql server administration

0 Answers  


How do I start and stop sql server?

0 Answers  


How does index makes search faster?

0 Answers   QuestPond,


CTE(common table expression)

1 Answers   Thomson Reuters,


You want to check the syntax of a complicated update sql statement without executing it. What command should you use?

0 Answers  


how do u do Performance tunning ?

1 Answers   Infodat Technologies, Satyam,


Is it possible to create tables in stored procedures using a variable for the table name?

2 Answers  


Categories