View Single Post

   
  #1 (permalink)  
Old 03-04-2008, 07:23 AM
Vic
 
Posts: n/a
Default help with stored procedure which returns an OUTPUT value

I am trying to figure out the solution for this stored procedure
Basically here is what i have in the stored procedure

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

CREATE PROCEDURE [dbo].[GetColumnName]
-- Add the parameters for the stored procedure here
@sTableName varchar(50),@sObjectClass varchar(50),@sFieldNumber
varchar(50), @sColumnName varchar(50) OUTPUT
AS
BEGIN
SET NOCOUNT ON;
set @sColumnName = ('select column_name FROM '+ @sTableName +
'.Information_Schema.columns '+'where Table_Name = '+''''+@sObjectClass
+''''+ ' and Column_Name like '+''''+@sFieldNumber+'-%''')
END

I call the Stored Procedure as
Declare @sColumnName varchar(50)
exec dbo.GetColumnName 'TestData6061','accounting','11',@sColumnName
OUTPUT
select @sColumnName
go

If I run
SELECT column_name
FROM TestData6061.Information_Schema.columns
where Table_Name = 'accounting' and Column_Name like '11-%' which is
what the stored procedure is doing, I get '11-AccountSpecifictype'.
What am I missing in the stored procedure that returns the value?
Please help. Thanks in advance
Reply With Quote