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

What is replication with database mirroring? : sql server database administration

1003


what is denormalization and when would you go for it? : Sql server database administration

1125


What is blocking?

1000


What are the properties and different types of sub-queries?

968


In how many ways you can invoke ssrs reports?

134


What is the Difference Between Primary and Foreign Key?

964


Explain what are page splits? : SQL Server Architecture

1013


What is row_number function?

949


Please differentiate between a local and a global temporary table?

961


What is the importance of concurrency control?

1182


What is an expression in ms sql server?

1025


What are the different types of cursor?

1046


what is the difference between them (ethernet networks and token ring networks)? : Sql server database administration

997


How to write character string constants or literals in ms sql server?

971


What is the exact numeric data type in sql?

969