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 |
What is the difference between a function and a trigger?
What method is used by the Command classes to execute SQL statements that return single values?
What is recompile sql server?
what is maximum size of temp db?
How can windows applications connect to sql servers via odbc?
What is the Difference Between Primary and Foreign Key?
0 Answers Accenture, Deloitte, JPMorgan Chase, Maveric,
What do you mean by stored techniques? How would we use it?
what is bit datatype and what's the information that can be stored inside a bit column? : Sql server database administration
How to add more data to the testing table in ms sql server?
Do you know hot add cpu in sql server 2008?
What is the query and subquery?
Why functions are used in sql server?
Oracle (3259)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)