-
can databse become a variable in store procedure
Hi I when my databse name become a variable , is that possible?
java code work fine
Code:
Sql+=" select FieldNumber, Name, HiTiter, SubType, Storage,SampleRegion, SampleYear";
Sql+=" from "+ourDatabase+".dbo.ViruName00";
but sql code not work
drop proc select_database
go
create proc select_database
(@database varchar(50),
@Name varchar(50)
)
AS
begin
begin transaction
select FieldNumber, Name, HiTiter, SubType, Storage,SampleRegion, SampleYear
from @databse.dbo.ViruName00
where Name like'%' +@Name+ '%'
any suggestions?
thank you
________
Design Host
Last edited by sql; 03-06-2011 at 01:51 AM.
-
You have to build the query string and use sp_executesql to execute it. SELECT statement does not accept variable name in from clause.
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|