Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Whats wrong with this stored procedure?

Author  Topic 

Mazdak
Yak Posting Veteran

63 Posts

Posted - 2003-02-23 : 03:16:36
Whats wrong with his stored procedure:

CREATE PROCEDURE sp_GetItemName
@Table nvarchar(50),
@ItemID bigint,
@ItemName nvarchar(100) output
AS

Declare @sqlstring AS nvarchar(1000)
Declare @columnname AS nvarchar(100)

set @sqlstring = 'SELECT '+ @columnname+ '=COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME=['+@Table+ '] AND ORDINAL_POSITION=9'
EXEC @sqlstring

DECLARE @sqlstring1 AS nvarchar(1000)
DECLARE @columnname1 AS nvarchar(100)
set @sqlstring1='SELECT ' +@ItemNAme+'=[' + @columnname + '] FROM [' + @Table + '] WHERE ID='+@ItemID
EXEC @sqlstring1
GO


When it run I got run time error:
Could not find stored procedure ''. Could not find stored procedure ''.

!!!!!!!!!!!!!!

macka
Posting Yak Master

162 Posts

Posted - 2003-02-23 : 05:07:35
Change the lines :

EXEC @sqlstring and EXEC @sqlstring1

to :

EXEC (@sqlstring) and EXEC (@sqlstring1)

The brackets indicate that a dynamic string should be executed rather than a stored proc.

macka.


--
There are only 10 types of people in the world - Those who understand binary, and those who don't.
Go to Top of Page
   

- Advertisement -