Click here to Skip to main content
11,926,933 members (54,644 online)
Rate this:
Please Sign up or sign in to vote.
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?

Posted 27-Nov-12 0:00am
Edited 27-Nov-12 1:26am
Maksud Saifullah Pulak 30-Nov-12 11:09am
You might use another connection string.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Try like below:

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

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.151126.1 | Last Updated 21 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100