Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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



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'
- Selecting the database name (GES)from the table
EXEC @StrConfig.dbo.pSEL_SyncTechItemLevelByUnitAndItemID


Msg 102, Level 15, State 1, Procedure pSEL_GlobalStocklist, Line 28
Incorrect syntax near '.'.

What's wrong with the Exec statment?

Thanks
Posted
Updated 27-Nov-12 0:26am
v2
Comments
Maksud Saifullah Pulak 30-Nov-12 11:09am    
You might use another connection string.

1 solution

Try like below:

SQL
DECLARE @sql NVARCHAR(1000)

SELECT @StrConfig=ConfigValue FROM lConfig WHERE ConfigName = 'GESDBName'
SET @sql='EXEC ' + @StrConfig + '.dbo.pSEL_SyncTechItemLevelByUnitAndItemID'
EXEC sp_executesql @sql
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900