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 use of except clause? How it differs from not in clause?

1061


What languages bi uses to achieve the goal?

1050


Why are you getting errors when creating a new odbc dsn?

1287


Where in ms sql server is ’100’ equal to ‘0’?

1130


What do you mean by SQL injection attack?

1124


What is a subquery in a select query statement in ms sql server?

1185


What is resource governor in sql server?

1048


Where is my database stored on the hard disk in ms sql server?

1107


How to list all objects in a given schema?

1104


Why use cursor in sql server?

1130


How to create and drop temp table in sql server?

1099


Write a program to fetch first 10 records from a file?

1062


What is SQL Azure Data sync?

123


Is sql server a database?

1037


What is the difference between Triggers and Stored Procedure?

1152