Click here to Skip to main content
12,949,826 members (80,166 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 26-Nov-12 23:00pm
Updated 27-Nov-12 0: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
OriginalGriff 5,489
CHill60 3,380
Maciej Los 2,913
Jochen Arndt 1,935
ppolymorphe 1,820

Advertise | Privacy | Mobile
Web01 | 2.8.170524.1 | Last Updated 21 Feb 2013
Copyright © CodeProject, 1999-2017
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