SQLServerCentral.com / SQL Server 2008 - General / SQL Server 2008 / SQL Server query Automation / Latest PostsInstantForum.NET v99.99.99SQLServerCentral.comhttp://www.sqlservercentral.com/Forums/notifications@sqlservercentral.comFri, 09 Dec 2016 20:52:58 GMT20RE: SQL Server query Automationhttp://www.sqlservercentral.com/Forums/Topic1379063-391-1.aspx[quote][b]krishna30 (10/30/2012)[/b][hr]I am kind of new in writing Procedure's or dynamic SQL's. Any suggestion that you could help me out with.[/quote]A procedure should do a single thing. The academic term is 'single responsibility'If writing in C# or java or the like, you wouldn't write a class that can do one of 20 things depending on the parameters, that would be against so many coding practices. Same thing with SQL, don't write a procedure that depending on the parameters passed selects an employee, updates an order, deletes a product or drops the database.Wed, 31 Oct 2012 01:15:14 GMTGilaMonsterRE: SQL Server query Automationhttp://www.sqlservercentral.com/Forums/Topic1379063-391-1.aspxI concur with Gail on this one. If you are trying to come up with a one time process to generate the delete statements to incorporate into some other type of code, then it might be worth considering. But if you are trying to repeat the delete statement generation process, you might want to rethink your design.Tue, 30 Oct 2012 18:02:29 GMTGeorge M ParkerRE: SQL Server query Automationhttp://www.sqlservercentral.com/Forums/Topic1379063-391-1.aspxI am kind of new in writing Procedure's or dynamic SQL's. Any suggestion that you could help me out with.This manual work is just making me go crazy :(Tue, 30 Oct 2012 17:47:14 GMTkrishna30RE: SQL Server query Automationhttp://www.sqlservercentral.com/Forums/Topic1379063-391-1.aspxI strongly recommend you do not go that design path. It's possible, it's not going to be fun and honestly it's not that good of an idea.Tue, 30 Oct 2012 16:58:16 GMTGilaMonsterRE: SQL Server query Automationhttp://www.sqlservercentral.com/Forums/Topic1379063-391-1.aspxWhat you are asking is possible through the blessing and curse of dynamic sql. before you start in on dynamic sql have a read through this as it has a detailed section on SQL Injection risks when using dynamic sql along with a good primer on dynamic sql.[url]http://www.sommarskog.se/dynamic_sql.html[/url]Tue, 30 Oct 2012 16:06:59 GMTCapnHectorSQL Server query Automationhttp://www.sqlservercentral.com/Forums/Topic1379063-391-1.aspxHi, I am testing one application I am preparing some queries as given belowStep1:SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE WHERE TABLE_NAME = 'CMC_PDRA_RATE_AGES'Step 1 OutputCOLUMN_NAME ___________HIST_ROW_ID PDRA_AGE_FROM PDRA_REF_DTM Step 2:Use the Columns name from step 1 and create a delte statement as given below.DELETE FROM [FACETS_TEST].CMC_PDRA_RATE_AGES WHERE HIST_ROW_ID = '' AND PDRA_AGE_FROM = '' AND PDRA_REF_DTM = '';I have about 300 tables like to do. Is there any automated SQL statement that someone can recommend.THanks,KrishnaTue, 30 Oct 2012 15:59:24 GMTkrishna30