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

List the various tools available for performance tuning?

0 Answers  


What is tabulation?

0 Answers  


How can u get the number of pupils connecting the database?

1 Answers   Cap Gemini,


what is web server?

3 Answers   Satyam,


On a windows server 2003 active – passive failover cluster, how do you find the node which is active?

0 Answers  


What are the OS services that the SQL Server installation adds?

3 Answers  


Which are the important points to note when multilanguage data is stored in a table?

0 Answers  


you added a row to a view, but the row is not shown on the view. Explain how this can happen, and how you can remedy the situation

0 Answers  


hi, i have a table called names and field name select * from names name a b c d i want to display like this name a,b,c,d how it is possible Regards Baiju

4 Answers  


State the difference between local and global temporary tables?

0 Answers  


How to download microsoft sql server 2005 express edition?

0 Answers  


What is row_number () and partition by in sql server?

0 Answers  


Categories