Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-server-2005
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 27-Nov-12 0:00am
JacoBosch1.4K
Edited 27-Nov-12 1:26am
v2
Comments
Maksud Saifullah Pulak at 30-Nov-12 11:09am
   
You might use another connection string.

1 solution

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

Solution 1

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
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 277
1 Maciej Los 220
2 DamithSL 190
3 Raul Iloc 185
4 Richard MacCutchan 175
0 OriginalGriff 5,130
1 DamithSL 4,197
2 Maciej Los 3,670
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,821


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 21 Feb 2013
Copyright © CodeProject, 1999-2014
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