0

I'm working on SQL Server to get the datas from one database and compare with another database. The database we have, has around 400's of table. I have to write a query to get all the table names based on the DB name, and having one column name, I have to get the datas from all the tables.

Still now, I have written a query to get the primary key value and to get the table names having that primary key value. My plan is to call the primary key details in first cursor, and within that create another cursor and fetch the details of the table name and column name.

Based on the values retrieved, I have to write a query to fetch the datas like "select * from @cursor_variable_tablename where primarykeyval = @cursor_variable_primarykeyval".

Is it possible to work like this by calling a variable instead of giving the table name.?

Please help me with this. Thanks In Advance.

1 Answer 1

1

Not sure what you are trying to achieve here but you can use dynamic sql to execute the query having table name as a variable.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your reply. I've used Dynamic SQL and executed.

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.