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 the difference between substr and charindex in the sql server?
After creating the cube, if we added a new column to the oltp table then how you add this new attribute to the cube? : sql server analysis services, ssas
What is the difference between delete and truncate statements?
You want to implement the one-to-many relationship while designing tables. How would you do it?
what are the critical issues you have resloved in your company
WHICH INDEX IS FAST CLUSTER AND NON CLUSTER INDEX
4 Answers CarrizalSoft Technologies, L&T,
write a query for list of owner who are having multiple bikes in below table 1 shanker pulsar 2 shanker Honda 3 shanker car 4 Balu pulsar 5 Balu Honda 6 Balu car 7 Shyam pulsar 8 Jaya Honda 9 Deepa car 10 vasu car
How to see the event list of an existing trigger using sys.trigger_events?
What is the use of commit?
What are subqueries in sql server?
Can we add a cpu to sql server?
Tell me about pre-defined functions of sql?