Hello,
I'm currently using stored procedures in my C# application to speed up the process of retrieving and manipulating data in the database. However I was wondering if the following is possible:
I have an assignment which has an ID, Year, Number, Description and Notes. I'm currently using a stored procedure for inserting new records in the database. But now I'm wondering if it is possible that when I insert a Year, Description and Notes in a new row, my stored procedure can automaticly return the ID and the Number.
The ID is a primary key which auto increments on each insert, and the Nr is beeing calculated in the following way:
SELECT ISNULL(MAX(Nr), 0) + 1 FROM Assignments WHERE Year = @Year;
This results that everytime a new year begins, the number counts from zero again while the ID keeps incrementing regardless of year. But it would be nice if the Inserted ID & Number could be automaticly returned.
Its for display stuff in the application to make it eaiser for the users to continue with that data instead of pulling a seperate query to retrieve that specific information.
I hope its clear what I'm trying to achieve
I'm currently using stored procedures in my C# application to speed up the process of retrieving and manipulating data in the database. However I was wondering if the following is possible:
I have an assignment which has an ID, Year, Number, Description and Notes. I'm currently using a stored procedure for inserting new records in the database. But now I'm wondering if it is possible that when I insert a Year, Description and Notes in a new row, my stored procedure can automaticly return the ID and the Number.
The ID is a primary key which auto increments on each insert, and the Nr is beeing calculated in the following way:
SELECT ISNULL(MAX(Nr), 0) + 1 FROM Assignments WHERE Year = @Year;
This results that everytime a new year begins, the number counts from zero again while the ID keeps incrementing regardless of year. But it would be nice if the Inserted ID & Number could be automaticly returned.
Its for display stuff in the application to make it eaiser for the users to continue with that data instead of pulling a seperate query to retrieve that specific information.
I hope its clear what I'm trying to achieve
Comment