How to pass schema as parameter to a stored procedure in sql server? -


i have stored procedure select list of data based on 2 tables. first table fixed one: co.country. second table can 1 of number of tables. name of table same: location. but, schema of tables different: abd.location, cga.location, gbn.location.

the user select schema application, schema chosen passed stored procedure parameter.

but there's error when parse stored procedure while creating it.

is there anyway pass schema name parameter?

use dynamicsql

try this

create procedure proc_name    @schema varchar(25)  declare @query varchar(1000) set @query='select * from' +@schema +'.location' execute(@query) 

Comments

Popular posts from this blog

c++ - Linked List error when inserting for the last time -

java - activate/deactivate sonar maven plugin by profile? -

java - What is the difference between String. and String.this. ? -