Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using literal values in Stored Procedure

Status
Not open for further replies.

MattDavies51

Programmer
Oct 13, 2002
24
GB
Hi, I'm hoping that somebody can help me here.

Basically, I'm passing the parameter @db_desc into a stored procedure. @db_desc is the name of a SQL Server database residing on the same SQL Server.

I want to use this parameter to identify the database in a select statement, like so:

select * from @db_desc..<table_name> where <expression>

Any ideas?
Regards
Matt
 
dynamic sql

Code:
create procedure sb_3(@db_desc varchar(128))
as
declare @s varchar(300)
set @s = 'select * from ' + @db_desc + '..<table_name> where <expression>'
exec(@s)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top