且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从一个数据库插入到其他数据库

更新时间:2023-01-12 14:13:52

尝试

 选择 @ fnmodule = DomesticFlag 来自 [DBA]。 [dbo] .Booking 其中 ClientID = '  044' 
选择 count(*)来自 [DBB]。[dbo] .Booking 其中​​ DomesticFlag = @ frmmodule
//现在检查 count 并且进行适当的处​​理。


USE [PhoenixVSSAccount]

GO

/ * *****对象:StoredProcedure [dbo]。[AccountInvoice]脚本日期:04/15/2014 15:12:25 ****** /

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

更改程序[dbo]。[AccountInvoice]



AS

BEGIN

声明@bookingID Int;

声明@fnmodule varchar(100);

声明@fnmodCode varchar(100);

声明@prefix varchar(20);

声明@CurrNumber varchar(100);

声明@IDMFlag varchar(20);



选择@ bookingID =来自Phoen的LastValue ixVSSAccount.dbo.SYS_PARAM其中KeyName ='BOOK'

set @ bookingID = @ bookingID + 1;



select @prefix = Prefix from phoenixoncloudv9.dbo.NumberRange其中ClientID ='044'且特殊='预订'



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



SELECT @ fnmodule =来自phoenixoncloudv9.dbo的DomesticFlag.Booking其中ClientID ='044'且Booking_ID = @CurrNumber



if(@ fnmodule ='0')

BEGIN

set @ fnmodCode ='DW';

set @ IDMFlag = '我';

打印@fnmodCode

结束

if(@ fnmodule ='1')

BEGIN

set @ fnmodCode ='IW';

set @ IDMFlag ='D';

print @fnmodCode;

print @CurrNumber;

END

END


我认为以下链接为您的问题提供了完整的解决方案 Sql面试问题和答案 [ Sql面试问题和答案]


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,

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

Try
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.


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


I think following link gives complete solution for your problem Sql interview questions and answers[Sql interview questions and answers]