I want to create a stored procedure based following way:
ALTER PROCEDURE spGetLastId
(
@table_name varchar(100)
)
AS
BEGIN
DECLARE @DBSql varchar(2000)
SET @DBSql = 'SELECT MAX(id) as ''LastId'' FROM ' + @table_name
EXEC sp_executesql @DBSql
END
This procedure will have to display the last id of any table that I pass as parameter.
Thanks and Regards,
Change @DBSql from varchar to nvarchar and that will work, alternatively look at the built-in IDENT_CURRENT().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With