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: 331495 # Views: 27 # Ratings: 0
Version: Visual FoxPro 9 SP2 Category: Databases, Tables and SQL Server
Date: Friday, December 30, 2011 1:52:49 PM         
   


> >
> > 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
>
>
> Hi,
> I am not using table_name as a variable name only the @database declared as a varchar(50). The table name is hard coded to be the actual table name.
> For sure you could create a string and run it....
>
> Declare @strSQL VarChar (MAX)
> Declare @DatabaseNameParameter VarChar (100) = 'TargetDatabaseName'
> SET @strSQL = 'SELECT * FROM ' + @DatabaseNameParameter + '.Schema.TableName'
>
>
> Here is another paramaterized example being run from sp_exectesql
> ----------------------------------------------------------------------------------------------
> Create PROCEDURE [dbo].[PersonAddress] (
> @AddressID int
> )
>
> AS
>
> declare @sql nvarchar(MAX)
>
> /*select * from Person.Address where AddressID = @AddressID */
>
> set @sql = N'select * from Person.Address where AddressID = @AddressID'
> exec sp_executesql @sql, N'@AddressID int', @AddressID
>
> Pete "the IceMan", from the Great White North of Canada.
> www.marathongriffincomputers.com

I have seen what you are doing and I meant it wouldn't work for name(s). I made a quick test and it didn't work for me. Maybe I am doing it wrong.



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