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 are the different index configurations a table can have?
What is the default value of CHAR type?
Give an example of SQL injection attack ?
What to perform pattern match with the like operator?
What is sub-query in sql server? Explain its properties.
What happens if null values are involved in arithmetic operations?
What do you understand by replication in sql server? Mention the different types of replication in sql server.
What's new in sql management studio for sql server? : sql server management studio
What is the syntax for encrypting a column in SQL Server?
How to connect sql server management studio express to sql server 2005 express?
How to reaname table name without using sp_Rename in sql server..?
How do I start sql server agent automatically?