0

@Table_R nvarchar(50)

FETCH NEXT FROM M_cursor INTO @M_col    

PRINT 'Mandatory Feilds ' + @M_col 

Select count(*) from @Table_R where @M_col is null'    


FETCH NEXT FROM M_cursor INTO @M_col 

I will send the table name as parameter ' @Table_R' , But in the cursor it throws an error.

  1. How to use dynamic table in the Sql Cursor.

thanks

1

2 Answers 2

2

You should use dynamic sql command sp_executesql (http://msdn.microsoft.com/en-us/library/ms188001.aspx). See example:

DECLARE @A numeric
EXEC SP_EXECUTESQL N'Select @a=count(*) from '+ @Table_R+ ' where ' + @M_col + ' is null',
      N'@A numeric OUTPUT', 
      @A OUTPUT;
Sign up to request clarification or add additional context in comments.

Comments

0

Replace

Select count(*) from @Table_R where @M_col is null

with

EXEC('Select count(*) from '+@Table_R+' where '+@M_col+' is null')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.