Click here to Skip to main content
15,895,784 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I wanted to read the last row a sql table which is having 10 coloumns (1-10) and write 5 coloumns (3-7) to another table of in row format in a single coloumn.

What I have tried:

I am new to SQL and have tried so many things from articles still not succeded.
Posted
Updated 25-Jul-18 6:50am
Comments
RedDk 25-Jul-18 15:51pm    
"Last row" because there's no index, right? Anyway, what RD says is partially ok but what I think you're going to have to do is use CONCATENATE on the return from multiple columns => to put into "single cloumn" as you say.

Is it possible to post some example data? Seeing "input" form is great but seeing "output" form is even better. That way there's no imagination involved.

1 solution

You need to break it into parts. To select the last row you need to determine how do you identify the last row. Hopefully you have an ID column that is an identity column so then it is really easy.
SQL
SELECT TOP 1
FROM table1 
ORDER BY ID DESC


To insert parts of this record into another table is very easy.
SQL
INSERT INTO table2 (field1, field2, field3)
SELECT TOP 1 field3, field4, field5) -- or whatever fields you want
FROM table1
ORDER BY ID DESC
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900