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 |
how to get the rowid/rownumbes of a table in sqlserver
What is normalization? What number of normalization shapes are there?
What do you mean by stored techniques? How would we use it?
What is intellisense?
What is a system database and what is a user database?
What is a livelock?
what is Constraint? How many types of constraints in SQL ?
38 Answers HCL, IBM, NIIT, Wipro,
What are dml triggers and types of dml triggers?
How to use user defined functions in expressions?
In performance wise distinct is good or group by is good? eg:select name from emp group by name; select distinct name from emp;
What is Peer to peer Replication?
1 Answers CarrizalSoft Technologies, HCL,
Explain linked server in sql?
Oracle (3253)
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)