Can anyone tell how correct the following code below. Iam tryin to create a stored procedure that returns the rowcount of a table whose name is passed to it.
CREATE PROCEDURE spROWCOUNTER
(
@tablename nvarchar(20)
@rowCountVal int OUTPUT
)
AS
DECLARE @strQuery nvarchar(300)
SET @strQuery = 'SELECT @rowCountVal=COUNT(*) FROM '+@tablename
EXEC(@strQuery)
RETURN @rowCountVal
ERROR MESSAGE :
- Incorrect syntax near '@rowCountVal'
- Must declare scalar variable '@tablename'
- Must declare scalar variable '@rowCountVal'
whereas the code below works fine
ALTER PROCEDURE spROWCOUNTER
(
@rowCountVal int OUTPUT
)
AS
SELECT @rowCountVal=COUNT(*) FROM DEFECT_LOG
RETURN @rowCountVal