我创建了以下存储过程..
CREATE PROCEDURE [dbo].[UDSPRBHPRIMBUSTYPESTARTUP]
(
@CODE CHAR(5)
, @DESC VARCHAR(255) OUTPUT
)
AS
DECLARE @SERVERNAME nvarchar(30)
DECLARE @DBASE nvarchar(30)
DECLARE @SQL nvarchar(2000)
SET @SERVERNAME =
Convert(nvarchar,
(SELECT spData FROM dbSpecificData WHERE spLookup = 'CMSSERVER'))
SET @DBASE =
Convert(nvarchar,
(SELECT spData FROM dbSpecificData WHERE spLookup = 'CMSDBNAME'))
SET @SQL =
'SELECT clnt_cat_desc FROM ' + @SERVERNAME +
'.' + @DBASE + '.dbo.hbl_clnt_cat WHERE inactive = ''N''
AND clnt_cat_code = ''' + @CODE + ''''
EXECUTE sp_executeSQL @SQL
RETURN
此过程用于许多不同的数据库和许多不同的服务器,并被编写为动态 SQL 以简化维护。该过程还在与该过程指向的服务器不同的服务器上运行。
我想将此过程的输出用作表中的值...
DECLARE @clid BIGINT
DECLARE @fileid BIGINT
DECLARE @myCode CHAR(5)
DECLARE @myDesc VARCHAR(255)
DECLARE @@tempDesc VARCHAR(255)
SET @clid = 1831400022
SET @fileid = 2072551358
SET @myCode =
(SELECT _clientPrimBusinessType FROM udbhextclient WHERE clid = @clid)
SET @myDesc =
EXEC UDSPRBHPRIMBUSTYPESTARTUP @CODE = @myCode, @DESC = @@tempDesc OUTPUT
----------------------------------------------------------------------------
SELECT
a.clid
, b.fileid
, c.usrfullname AS ClientPartner
, e.usrfullname AS ClientFeeEarner
, @myDesc AS ClientPrimaryBusinessType
FROM
dbclient a
INNER JOIN
dbFile b
ON
a.clid = b.clid
INNER JOIN
dbuser c
ON
a.feeusrid = c.usrid
INNER JOIN
udbhextclient d
ON
a.clid = d.clid
INNER JOIN
dbuser e
ON
d._ClientFeeEarner = e.usrid
WHERE
a.clid = @clid
AND b.fileid = @fileid
我知道这是不正确的语法,但是您可以看到我正在尝试实现这一点而无需使用临时表,因为这意味着要在 30 台不同的服务器上进行维护,每台服务器上有 3 到 5 个数据库。
Smink - 尝试了您的解决方案并得到以下结果......