.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> DataBase >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Simple Dynamic query sample

Posted By:shankey       Posted Date: April 25, 2011    Points: 200    Category: DataBase    URL: http://www.dotnetspark.com  

In this article I will show Simple Dynamic query sample in SQL server.
 

Simple Dynamic query sample


Following example fetch details from the system table "TABLES" which is under schema "INFORMATION_SCHEMA"
1)  Dynamic query which fetches all columns from the table


Here @columns is set to '*' which means fetch all the columns



 Print @sql statement in the above statement output the following query



Following is the result of exec(@sql)




2)  Dynamic query which fetches "TABLE_CATALOG" column from the table

Here @columns is set to "TABLE_CATALOG"  which means fetch "TABLE_CATALOG"  column.



Print @sql statement in the above statement output the following query


Following is the result of exec(@sql)



3)  Dynamic query which fetches "TABLE_SCHEMA" column from the table

Here @columns is set to "TABLE_SCHEMA"  which means fetch "TABLE_SCHEMA"  column.



 Print @sql statement in the above statement output the following query



Following is the result of exec(@sql)




4)  Dynamic query which fetches "TABLE_NAME" column from the table
Here @columns is set to "TABLE_NAME"  which means fetch "TABLE_NAME"  column.



Print @sql statement in the above statement output the following query



Following is the result of exec(@sql)



5)  Dynamic query which fetches "TABLE_TYPE" column from the table


Here @columns is set to "TABLE_TYPE"  which means fetch "TABLE_TYPE"  column.



Print @sql statement in the above statement output the following query




Following is the result of exec(@sql)



 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend