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 August 24th, 2004, 12:10 PM
Registered User
 
Join Date: Aug 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default get calling database name

I'm having trouble getting the current database name when calling a stored procedure. My stored procedure drops tables in the database when the name of the table is a match. I do not want to have to pass the current database name into the stored procedure. The problem is happening where I'm calling the stored procedure to do this in a database that is different from the database that has the tables I want to drop.

I've tried using set @d_name = (SELECT DB_NAME()) within my stored procedure to get the name of the current database, but it keeps getting the name of the database the stored procedure is in. Any ideas?

 
Old August 26th, 2004, 01:23 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 625
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jemacc
Default

Post your full select statement. you may need to select three part name in your select. (select objectname from database.dbo.objectname)

 
Old September 4th, 2004, 02:45 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

espin,

Yes, unless we see your full code, it is not easy to suggest any way.

As Far As I Understood your post, I dont think you can do it the way you are trying to.

Assume you are into db2 now and the stored proc is in db1

use db2
go

Execute db1.dbo.storedprocname
go

Still it would use the DB_NAME() as db1, as stored proc is an object of db1. May be replicating the SP to the db2 would solve your problem.

Hope that helps.
Cheers!

_________________________
- Vijay G
Strive for Perfection





Similar Threads
Thread Thread Starter Forum Replies Last Post
calling a sub collatos BOOK: Beginning Microsoft Visual Basic 2008 ISBN: 978-0-470-19134-7 1 October 3rd, 2008 02:07 PM
Calling on a database within a stored procedure Hadware SQL Language 1 January 8th, 2007 05:11 PM
Calling activeX from c# jinohere Beginning VB 6 1 August 29th, 2006 10:39 AM
Calling C# from C NoXuS C# 10 May 12th, 2006 10:40 AM
calling a form melvik C# 4 July 23rd, 2003 05:24 AM





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