从另一个数据库执行Short过程 [英] Execute Short procedure from another database
问题描述
美好的一天
我创建了一个存储过程,从另一个数据库执行另一个存储过程。
此声明100%正常工作。
Good day
I have created a stored procedure that executes another stored procedure from a different database.
This statement is working 100%.
EXEC GES.dbo.pSEL_SyncTechItemLevelByUnitAndItemID
我想在select语句中选择不同的数据库名称时调用存储过程,并在exec中调用select语句。
当我执行以下语句时,我收到错误。
I want to call a stored procedure when selecting a different database name in a select statement and call the select statement in exec.
When I do the following statements I get an error.
SELECT @StrConfig=ConfigValue FROM lConfig WHERE ConfigName = ''GESDBName''
- 从表中选择数据库名称(GES)
- Selecting the database name (GES)from the table
EXEC @StrConfig.dbo.pSEL_SyncTechItemLevelByUnitAndItemID
消息102,等级15,状态1,程序pSEL_GlobalStocklist,第28行
'。''附近的语法不正确。
Exec声明有什么问题?
谢谢
Msg 102, Level 15, State 1, Procedure pSEL_GlobalStocklist, Line 28
Incorrect syntax near ''.''.
What''s wrong with the Exec statment?
Thanks
推荐答案
尝试如下:
Try like below:
DECLARE @sql NVARCHAR(1000)
SELECT @StrConfig=ConfigValue FROM lConfig WHERE ConfigName = 'GESDBName'
SET @sql='EXEC ' + @StrConfig + '.dbo.pSEL_SyncTechItemLevelByUnitAndItemID'
EXEC sp_executesql @sql
这篇关于从另一个数据库执行Short过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!