You are here: Re: STORED PROCEDURE - passing table name as a parameter « MsSQL Server « IT news, forums, messages
Re: STORED PROCEDURE - passing table name as a parameter

Posted by Erland Sommarskog on 10/04/21 11:33

Steve (sjc4914@yahoo.com) writes:
> This looks somewhat promising. I'll give it a try over the weekend and
> let you know how if it works out. I tried to move from a stored
> procedure to a stored function yesterday and ended up frustrated. I
> could almost get it to work, but I couldn't come up with a way to return
> the scalar value from the EXECUTE @sql.

You can use sp_executesql for that:

EXEC sp_executesql N'SELECT @cnt = COUNT(*) FROM tbl', N'@cnt int OUTPUT',
@cnt = @count OUTPUT

However, you cannot use dynamic SQL in user-defined functions.



--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

 

Navigation:

[Reply to this 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

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