I have the table which contains the table's id and name.
Now I want to retrieve the table names by passing table ID to the stored procedure.
Example:
create procedure spGetAllTables
@TableIDs varchar(max)
AS
DECLARE @Tables varchar(max)
DECLARE Cur1 CURSOR FAST_FORWARD FOR
SELECT TableName FROM TablesContainer
WHERE TableID IN (@TableIDs)
OPEN Cur1
FETCH NEXT FROM Cur1 INTO @Tables
WHILE(@@FETCH_STATUS=0)
BEGIN
PRINT(@Tables)
FETCH NEXT FROM Cur1 INTO @Tables
END
CLOSE Cur1;
DEALLOCATE Cur1;
GO
Explanation: The table TablesContainer
contains all table's ID's and table's names. I just want to print all those table names which I have passed their table ID's to the stored procedure.
The procedure working fine if I pass single value to the variable @TableIDs
. But If I pass multiple values like 1,2,3
to @TableIDs
then its not getting entered into the cursor
.