You are here: Re: I want to return a string to a wrapper from a subordinate stored procedure « MsSQL Server « IT news, forums, messages
Re: I want to return a string to a wrapper from a subordinate stored procedure

Posted by bobc on 09/28/07 14:56

On Sep 27, 5:38 pm, Erland Sommarskog <esq...@sommarskog.se> wrote:
> bobc (bcana...@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, esq...@sommarskog.se
>
> Books Online for SQL Server 2005 athttp://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books...
> Books Online for SQL Server 2000 athttp://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

Thanks very much, Erland! -BobC

 

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

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