Click here to Skip to main content
15,895,709 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Dear Team

I am facing problem to call from one database to other, we have two different database, from databaseA it has to be select Fnmodule and this value should be check in databaseB. I Tried below method I am getting error,please help me to resolve this issue,

SQL
Create PROCEDURE [dbo].[AccountInvoice1]     

AS  

BEGIN    
 Declare @fnmodule varchar(100) 

 SET NOCOUNT ON;     

    use databaeA

     select  @fnmodule=DomesticFlag from Booking where ClientID='044'

     use databaseB

 SELECT  FNMDId from GenFunction where FNMODULE=@fnModule  

END
Posted
Updated 14-Apr-14 22:11pm
v2
Comments
Herman<T>.Instance 15-Apr-14 4:14am    
are both databases on the same server?
has the user rights on both database?
are you familiar with [databasename].[dbo].[tablename]?

Try
SQL
select  @fnmodule=DomesticFlag from [DBA].[dbo].Booking where ClientID='044'
select count(*) from [DBB].[dbo].Booking where DomesticFlag = @frmmodule
//Now check for count and do appropriate processing.
 
Share this answer
 
v2
USE [PhoenixVSSAccount]
GO
/****** Object: StoredProcedure [dbo].[AccountInvoice] Script Date: 04/15/2014 15:12:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[AccountInvoice]

AS
BEGIN
Declare @bookingID Int;
Declare @fnmodule varchar(100);
Declare @fnmodCode varchar(100);
Declare @prefix varchar(20);
Declare @CurrNumber varchar(100);
Declare @IDMFlag varchar(20);

select @bookingID= LastValue from PhoenixVSSAccount.dbo.SYS_PARAM where KeyName='BOOK'
set @bookingID=@bookingID+1;

select @prefix =Prefix from phoenixoncloudv9.dbo.NumberRange where ClientID='044' and Particular='Book'

set @CurrNumber = @prefix+''+CONVERT(varchar,@bookingID);

SELECT @fnmodule= DomesticFlag from phoenixoncloudv9.dbo.Booking where ClientID='044' and Booking_ID=@CurrNumber

if(@fnmodule='0')
BEGIN
set @fnmodCode='DW';
set @IDMFlag='I';
print @fnmodCode
END
if(@fnmodule='1')
BEGIN
set @fnmodCode='IW';
set @IDMFlag='D';
print @fnmodCode;
print @CurrNumber;
END
END
 
Share this answer
 
I think following link gives complete solution for your problem Sql interview questions and answers[Sql interview questions and answers]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900