SJJ9166
SJJ9166

Reputation: 73

How to run SQL statement from within Stored Proc based on parameter

Can someone post an example of a stored proc that runs a SQL statement based on parameter?

I have 6 flatfile that are loaded into 6 different staging tables.

Each staging tables requires transformations prior to loading into production table.

Can I create a single spoc that runs specific SQL based on passed in parameter?

For example Exec Sproc_Transform stage_table1

This would run sql statement specific to stage_table1

What is the best approach?

Thanks

Upvotes: 0

Views: 38

Answers (1)

Jesse
Jesse

Reputation: 873

There is a lot of ways of doing this. To answer your question directly:

create procedure usp_ProcNamehere
    @Param1 varchar(10)

as
begin

set nocount on

if @param1='Table1'
begin
    select * from table2
    update a set id = null from table2
end
else if @param2='Table2'
begin
    select * from table2
end


end

Upvotes: 1

Related Questions