Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 6th, 2006, 03:56 PM
Registered User
 
Join Date: Dec 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Varible DB Name

We save our DBs at month end and have that DB available with the name "Service_YYYYMMDD". I need to join from the active DB to a previous DB.

FROM Service_20050401.dbo.Company C2,Service_20050908.dbo.Company C, Service_20050908.dbo.Loan L
  INNER JOIN Service_20050908.dbo.Status S ON L.LoanID=S.LoanID
  INNER JOIN Service_20050401.dbo.Loan L2 ON L.LoanID=L2.LoanID
  INNER JOIN Service_20050401.dbo.Status S2 ON L.LoanID=S2.LoanID

Is there a way to program the DB name as a parameter that can be pulled into the view/procedure so that I don't have to physical change the view each time before executing? I used to program in SAS and it is possible in SAS to do this.

 
Old December 7th, 2006, 01:21 AM
Registered User
 
Join Date: Dec 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ghemant
Default

refer sommarskog's dynamic Sql for more.

With Regards
Hemantgiri S. Goswami
------------------------
"Humans don't have Caliber to PASS TIME , Time it self Pass or Fail Humans"  -Hemantgiri S. Goswami
 
Old December 7th, 2006, 10:19 PM
Registered User
 
Join Date: Dec 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to emcarandang
Default

MDingler,
My friend, it is possible to use dbo.***** for inParameter/s. Since i am into UDF and not much into stored procedure, this is how i do it with UDF.
================================================== =============
Please execute this with caution this is dangerous. just get the idea and NEVER EXECUTE THIS!!!!!!!!!!!!!!!!!!!!!
================================================== =============
--The following is the CREATE FUNCTION script for udf_Func_UndocSystemUDFText
--It's commented out to prevent accidental creation.
CREATE FUNCTION dbo.udf_Func_UndocSystemUDFText
(
@FunctionName sysname --name of the function
)
RETURNS @Script TABLE --text of the function
    ([text] varchar(4000)) --a line of text

--No SCHEMABINDING due to the use of system tables
--Returns the text of an undocumented system user-defined function.
--This function can only be used in the master database, where the text
--of the undocumented UDFs is stored.

AS
BEGIN
  DECLARE @objectID int
  SELECT @objectID = id
    FROM sysobjects
    WHERE (type=N'FN' or type=N'IF or type = N'TR')
      AND name = @FunctionName
  INSERT INTO @Script
    SELECT [text]
      FROM syscomments
        WHERE id = @objectID
  RETURN
END
================================================== =============
In your case use @SP_Name instead of @FunctionName... Again, use this as reference and do it with caution!!!!!!!!!!!!!


#9562;Ä{ôƒ#9573;#9500;
 
Old December 7th, 2006, 10:21 PM
Registered User
 
Join Date: Dec 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to emcarandang
Default

MDingler,

Eratum:
It should be @DBName and not....@FunctionName
.....
.....
" RETURN
END
================================================== =============
In your case use @SP_Name instead of @FunctionName... Again, use this as reference and do it with caution!!!!!!!!!!!!!"

#9562;Ä{ôƒ#9573;#9500;





Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding the DB Sailor.mdb of Beginning ASP DB book anna Classic ASP Databases 2 August 5th, 2006 01:13 PM
Using a varible to filter XML output animus XML 0 March 1st, 2006 02:49 PM
Passing a ASP varible to a javascript tdaustin Classic ASP Basics 1 May 17th, 2005 01:44 AM
Unique Control IDs inside a loop using a varible Joshua Sebastian Classic ASP Basics 2 February 3rd, 2005 10:44 AM
Varible mrideout BOOK: Beginning ASP.NET 1.0 3 July 22nd, 2004 01:57 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.