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 Deadlock?
What are the restraints imposed on the table design by a merge replication?
Explain how to maintain a fill factor in existing indexes?
What are relationships and mention different types of relationships in the dbms
How will you go about resolving deadlocks?
how do we find every fifth record in a table
Explain important index characteristics?
What is the use of keyword with encryption.
How to change the data type of an existing column with "alter table" statements in ms sql server?
Is resultset an interface?
How to copy the tables, schema and views from one sql server to another?
What are the properties and different types of sub-queries?