Hi,

Does anyone know how to pass table name as parameter in a cursor?

ALTER PROCEDURE [dbo].[error_calculation]
@tablename nvarchar(50)
AS
DECLARE @part_no nvarchar(50)

--Current Year Cursor
DECLARE db_cursorpartno CURSOR 
FOR  
select  distinct part_no from @tablename ///This gives error
OPEN db_cursorpartno
FETCH FROM db_cursorpartno INTO @part_no

You can only do that if you build your query as a string and execute it with sp_executesql

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.