A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
Hi @Bone_12 ,
Welcome to the microsoft TSQL Q&A forum!
Your question is related to TSQL. My colleague helped you add the TSQL tag.
I see that you have 0 as comp_rep_no in the first SELECT statement, so comp_rep_no will definitely return a value of 0.
When you insert the value into the [comp].[dbo].[Staff_log] table, the result you return is only one row. If you don't have a qualification, it will randomly return one row.
Maybe this is what you want:
select top(1)*
from [comp].[dbo].[Staff_log]
order by comp_rep_no DESC
If this does not solve your problem,please share us your table structure (CREATE TABLE …) and some sample data(INSERT INTO …)along with your expected result. So that we’ll get a right direction and make some test.
Regards
Echo
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.