本文介绍了从一个数据库插入到其他数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 亲爱的团队 我面临从一个数据库调用到其他数据库的问题,我们有两个不同的数据库,从databaseA它必须选择Fnmodule和这个值应该检查数据库B.我尝试下面的方法我收到错误,请帮我解决这个问题, 创建 PROCEDURE [dbo]。[AccountInvoice1] AS BEGIN 声明 @ fnmodule varchar ( 100 ) SET NOCOUNT ON ; 使用 databaeA 选择 @ fnmodule = DomesticFlag 来自预订其中 ClientID = ' 044' 使用 databaseB SELECT FNMDId 来自 GenFunction 其中 FNMODULE = @ fnModule END 解决方案 尝试 选择 @ 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 TeamI 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]ASBEGIN 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=@fnModuleEND 解决方案 Tryselect @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 ONGOSET QUOTED_IDENTIFIER ONGOALTER PROCEDURE [dbo].[AccountInvoice]ASBEGINDeclare @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=@CurrNumberif(@fnmodule='0')BEGINset @fnmodCode='DW';set @IDMFlag='I';print @fnmodCodeENDif(@fnmodule='1')BEGINset @fnmodCode='IW';set @IDMFlag='D';print @fnmodCode;print @CurrNumber;ENDENDI think following link gives complete solution for your problem Sql interview questions and answers[Sql interview questions and answers] 这篇关于从一个数据库插入到其他数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-11 17:04