Click here to Skip to main content
11,479,096 members (63,690 online)
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.5K
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 Sergey Alexandrovich Kryukov 215
1 F-ES Sitecore 195
2 OriginalGriff 185
3 Frankie-C 120
4 DamithSL 85
0 Sergey Alexandrovich Kryukov 7,890
1 OriginalGriff 7,366
2 Sascha Lefèvre 3,064
3 Maciej Los 2,491
4 Richard Deeming 2,335


Advertise | Privacy | Mobile
Web04 | 2.8.150520.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