Reply to Re: Function Parameter

Your name:

Reply:


Posted by Paul on 04/20/07 11:13

Hi,

I would do it using a procedure as follows:

CREATE PROCEDURE GetFieldValue
@strTableName VARCHAR(250),
@strFieldName VARCHAR(250),
@nID DECIMAL(9,0),
@strResult VARCHAR(250) OUTPUT
AS
BEGIN
DECLARE @strSQL NVARCHAR(4000)

SET @strSQL = 'SELECT @strResult = ' + @strFieldName
+ ' FROM ' + @strTableName
+ ' WHERE ID = ' + CAST (@nID AS VARCHAR(9))

EXEC sp_executesql @strSQL,
N'@strResult VARCHAR(250) OUTPUT',
@strResult OUTPUT
END
GO

And then execute it in a way like this:

DECLARE
@strValue VARCHAR(250)

BEGIN

EXEC dbo.GetFieldValue 'TABLE1', 'COLUMN1', 1, @strValue OUTPUT

PRINT @strValue
END
GO

Obviously the print is just to ensure that you have the correct value.
This may not be the best way, but it's a way that works for me.

Hope this helps,

Paul

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация