How can you swap values between two rows in a table using single- SQL statement?
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 |
can an order by clause be used in a creation of a view?
Do you know what is xpath?
Explain features of analysis services?
How to list all triggers in the database with sys.triggers in ms sql server?
Explain the collation?
In the primary key have a multiple field or not?
List out the difference between union and union all in sql server?
Delete duplicate records from the table?(Table must have unique id)
7 Answers TCS, Thomson Reuters,
How to find the date and time of last updated table?
What is the xml datatype?
What can be used instead of trigger?
What is @@error in sql?