如何在存储过程中使用两个数据库并获得返回 [英] How to use two Databases in a stored procedure and get return
本文介绍了如何在存储过程中使用两个数据库并获得返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在存储过程下面发布
首先,我试图在客户端数据库中找到记录,如果没有找到那么
在主数据库中搜索它。
在ASP应用程序中使用存储过程。
请帮助获取没有任何输出参数的返回值
ALTER PROCEDURE [dbo].[app_AuthenticateEmailCount]
@Email varchar(50)
AS
BEGIN
DECLARE @TotalCRecords varchar(10);
DECLARE @TotalMRecords varchar(10)
set @TotalCRecords = 'SELECT COUNT(*) AS TotalCRecords FROM ff_fvdcbdev.dbo.app_User cu inner join ff_fvdcbdev.dbo.app_Person cp on cu.idUser = cp.idUser
WHERE cp.emailAddress =' + @Email
IF (@TotalCRecords = '0')
set @TotalMRecords = 'SELECT COUNT(*) AS TotalMRecords FROM freefunds.dbo.app_User mu inner join freefunds.dbo.app_Person mp on mu.idUser = mp.idUser
WHERE mp.emailAddress =' + @Email
推荐答案
尝试UNION
:
TryUNION
:
SELECT 'CRecords' as [Type], COUNT(*) AS [Count] FROM ff_fvdcbdev.dbo.app_User cu inner join ff_fvdcbdev.dbo.app_Person cp on cu.idUser = cp.idUser
WHERE cp.emailAddress = @Email
UNION
SELECT 'MRecords' as [Type], COUNT(*) AS [Count] FROM freefunds.dbo.app_User mu inner join freefunds.dbo.app_Person mp on mu.idUser = mp.idUser
WHERE mp.emailAddress = @Email
这篇关于如何在存储过程中使用两个数据库并获得返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文