Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Cetin Basoz
  Where is Cetin Basoz?
 Izmir
 Turkey
 Cetin Basoz
 To: Pete Sass
  Where is Pete Sass?
 Marathon, Ontario
 Canada
 Pete Sass
 Tags
Subject: RE: SQL Server database name as variable
Thread ID: 331130 Message ID: 331187 # Views: 53 # Ratings: 1
Version: Visual FoxPro 9 SP2 Category: Databases, Tables and SQL Server
Date: Tuesday, December 27, 2011 4:41:52 PM         
   


> > How to use a variable to refer to a database name in stored procedures on SQL Server?
> >
> > Regards,
> > Nilson
>
>
> Hi,
>
> Maybe something like this will work?
>
> CREATE PROCEDURE dbo.stored_procedure_name
> AS
>
> DECLARE @database varchar(50)
> SET @database = (SELECT dbName FROM database.currentDatabase)
>
> Begin
>
> set nocount on
> select * from (@database).dbo.table_name
>
> End
> GO
>
> Pete "the IceMan", from the Great White North of Canada.
> www.marathongriffincomputers.com

Pete,
Do you think that really would work? AFAIK you are not allowed to use db, table ... names as variables like this. You can construct a string and run with sp_executesql maybe.



Cetin Basoz

.Net has got better.Think about moving - check my blog:
My Blog
Blog (mirror) - sounds to be down


Support Wikipedia

ENTIRE THREAD

SQL Server database name as variable Posted by Nilson Rishi @ 12/27/2011 7:36:00 AM
RE: SQL Server database name as variable Posted by Pete Sass @ 12/27/2011 2:50:38 PM
RE: SQL Server database name as variable Posted by Cetin Basoz @ 12/27/2011 4:41:52 PM
RE: SQL Server database name as variable Posted by Pete Sass @ 12/27/2011 5:51:56 PM
RE: SQL Server database name as variable Posted by Cetin Basoz @ 12/30/2011 1:52:49 PM
RE: SQL Server database name as variable Posted by Pete Sass @ 12/30/2011 6:11:09 PM
RE: SQL Server database name as variable Posted by Pete Sass @ 12/30/2011 6:50:34 PM
RE: SQL Server database name as variable Posted by Nilson Rishi @ 12/30/2011 9:24:36 AM
RE: SQL Server database name as variable Posted by Pete Sass @ 12/30/2011 10:11:40 AM
RE: SQL Server database name as variable Posted by Nilson Rishi @ 12/31/2011 7:05:27 AM