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 |
Write the queries for commands like Create Table, Delete table, Drop Table etc.
0 Answers HPCL, Hughes Systique Corporation,
Explain system functions or built-in functions? What are different types of system functions?
How to find the date and time of last updated table?
How do you find value of first column before inserting value into the second column in the same table for checking that second column must have different value than first column.
how do u do Performance tunning ?
1 Answers Infodat Technologies, Satyam,
Can you use order by when defining a view?
How many types of local tables are there in sql server?
How does stuff differ from the replace function?
How can I track the changes or identify the latest insert-update-delete from a table?
Describe in brief databases and sql server databases architecture.
what is a join and explain different types of joins? : Sql server database administration
How to select top 5 coloumn from a table without using coloumn name