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


Hi,

This is what I did was create the stored procedure using the SQL Server Management Studio as shown below.

CREATE PROCEDURE sp_Griffin
     @DBName sysname
  AS 
  DECLARE @cmd nvarchar(2000) 
  SET @cmd = N'SELECT * FROM ' + @DBName + '.dbo.Griffin' 
  exec (@cmd) 
  GO

You have to use dynamic SQL. Security risks exist on using dynamic SQL as
the user who runs the procedure much have access to the table or tables
listed in the dynamic SQL. Dynamic SQL is subject to a SQL injection attack.

Then I connected to SQL Server using SQLStringConnect() from with Visual Foxpro.

Then I called the sp_Griffin stored procedure passing the database of Griffin in VFP code. Note: I removed my error checking below to show only main code.
sqlcomm = "execute sp_Griffin 'Griffin'"
=SQLExec(nSQLconn,sqlcomm)  && Where nSQLconn is my connection handle.
BROWSE  && Browse the resulting table or do what-ever.

Pete "the IceMan", from the Great White North of Canada.
www.marathongriffincomputers.com

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