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 collation sensitivity? Explain different types.
What are the difference between “where” and “having” clause in sql server?
What is normalization? Describe its different types.
explain different types of backups avaialabe in sql server? : Sql server database administration
What are the steps to insert a table?
Explain the use of keyword with encryption. Create a store procedure with encryption?
How to execute multiple stored procedures at one time in sql server?
Define cursor locking
Describe triggers features and limitations?
Explain what is the purpose of sql profiler in sql server?
Why we should not use triggers?
What are indexes? When do you need to create Indexes?
4 Answers CarrizalSoft Technologies, HP,