Reply to Re: I want to return a string to a wrapper from a subordinate stored procedure

Your name:

Reply:


Posted by Erland Sommarskog on 09/27/07 21:38

bobc (bcanavan@fmbnewhomes.com) writes:
> The Wrapper:
> -----------------------------------------------------------------
> CREATE PROCEDURE wrapper
> @lString varchar(255) OUT
> AS
>
> EXEC @lString = sub_proc @CommCode, @lString OUT
> GO

Remove "@lString =". The return value from a stored procedure is
always integer, and customary you use it to return success/failure
indication, with 0 meaning success.

> DECLARE @var1 int,
> @var2 int
>
> SELECT @var1 =
> (SELECT count(mycolumn)
> FROM mytable
> WHERE condition=1)
>
> SELECT @var2 =
> (SELECT count(mycolumn)
> FROM mytable
> WHERE condition=2)

Rather you can do:

SELECT @lString =
ltrim(str(SUM(CASE condition WHEN 1 THEN 1 ELSE 0 END)) + '.' +
ltrim(str(SUM(CASE condition WHEN 2 THEN 1 ELSE 0 END)) + '.' +
...
ltrim(str(SUM(CASE condition WHEN 7 THEN 1 ELSE 0 END))
FROM mytable
WHERE mycolumn IS NOT NULL
AND condition BETWEEN 1 AND 7

--
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

[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

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