.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
MarieAdela
Imran Ghani
Post New Web Links

How to get total record count in an OUTPUT Parameter

Posted By:      Posted Date: September 30, 2010    Points: 0   Category :Sql Server
 

I couldn't get the total record count in a, in my stored proc, in a given scenario. Please help

 

My SP looks like this:

create proc RecordCount

       @CustomerID varchar(10),

       @RecCnt int OUTPUT

as

begin tran

if(CustomerID = 'ABC')

@RecCnt = select count(*) from Customers where CustomerID='ABC'

commit

 

begin tran

if(customerID='XYZ')

@RecCnt = select count(*) from Customers where CustomerID='XYZ' and TranDate > '05/01/2009'

commit

GO

 

-- This is how I called my SP

declare @rc int

exec RecordCount 'XYZ', @RecCnt = @rc OUTPUT

select @rc




View Complete Post


More Related Resource Links

Enterprize library 4.1 getting output parameter after adding record in db, plz guide

  

Hi,

I need to get output parameter (flag) from db after saving record in database. I am using Microsoft Enterprise Library 4.1 for DB. I am inserting record using I Data reader.

Please guide

Thanks


output cache to be used only when parameter has changed + old question of user control not answered

  

hello,

i have 2 questions about output cache:

1.is it just me , or does it seems that it is used only after the second time that the user reaches the webpage? if so, why, and how can i tweak it to my needs? my guess is that it wouldn't be logical to cache every time a user reach a webpage, but only when it happens enough times.

2.i know that i can use "varybyparam" for using the output cache when the parameter doesn't change , but it seems that it would use the output cache even if there is no parameter , or if the specified paramter is not there. is there a way to overcome this?

3.an old question that somehow marked as "answered" , yet i didn't solve : suppose i created a user control and i gave it values through the CTOR via the aspx file . is it possible to show the values from within the split/design mode? remember that i've talking about ASP.NET and not simply C# winforms . i write this because this question was on :

http://forums.asp.net/t/1588671.aspx

and the answer that i got was for C# and winforms . i've tried to do the same for ASP.NET , but i've failed.

can anyone please help me?


optional output parameter in CLR Stored Procedure

  
I'm trying to transpose a Procedure that sends mail via CDO.Message and Ole Automation to a .Net CLR Procedure. this procedure must have the same parameters in the same order as the original to maintain compatibility with everything that already uses it. the declaration goes as follow   <Microsoft.SqlServer.Server.SqlProcedure(name:="SP_ENVIAEMAIL")> _<br/> Public Shared Sub ENVIAEMAIL(<SqlFacet(MaxSize:=100)> Optional ByVal De As String = "", <SqlFacet(MaxSize:=100)> Optional ByVal Para As String = "", _<br/> <SqlFacet(MaxSize:=100)> Optional ByVal Copia As String = "", <SqlFacet(MaxSize:=100)> Optional ByVal Oculta As String = "", _<br/> <SqlFacet(MaxSize:=100)> Optional ByVal Assunto As String = "", <SqlFacet(MaxSize:=-1)> Optional ByVal Mensagem As String = "", _<br/> <SqlFacet(MaxSize:=-1)> Optional ByVal Anexo As String = "", _<br/> <strong><SqlFacet(MaxSize:=1000)> <Out()> Optional ByVal Retorno As String = ""</strong> , _<br/> <SqlFacet(MaxSize:=100)> Optional ByVal Smtp As String = "", <SqlFacet(MaxSize:=100)> Optional ByVal Usuario As String = "",

output parameter sp/c#

  
 Hi I have a problem getting my code right. I got "String[1]: the Size property has an invalid size of 0." in my c# code. SP:SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE sp_GetUserName ( @UserNames UserNamesType READONLY, @tmpUserNames nvarchar(max) OUTPUT) AS BEGIN SET NOCOUNT ON; DECLARE @tmpUser nvarchar(max); SELECT @tmpUser = (FirstName + ' ' + LastName + ',') FROM Users WHERE [Login] = (SELECT UserName FROM @UserNames) SET @tmpUserNames = @tmpUser RETURN END GO   public static string GetUserName(DataTable dtUser) { string err = String.Empty; string userResult; string sqlText = "sp_GetUserName"; try { using (SqlCommand cmd = new SqlCommand(sqlText, connect.GetSqlConnection(out err))) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@UserNames", SqlDbType.Structured).Value = dtUser; cmd.Parameters.Add("@tmpUserNames", SqlDbType.Text).Direction = ParameterDirection.Output; cmd.ExecuteNonQuery(); userResult = (string)cmd.Parameters["@tmpUserNames"].Value; return userResult; } } catch (SqlException ex) { return null; } } Can someon

SQL Server 2008 Stored Procedure output parameter

  
I would like to get OUTPUT parameter names from stored procedure without executing stored procedure.  for excample schema API will help to get input parameter metadata. Thanks in advance. Murali

How to get input parameter's count and type by using MetadataImporter

  
I want to get each input parameter type of all operations in WCF Service via MetadataImporter, the code as below: Service Contract: it is default after you created a wcf applicaiton in vs 2010     [ServiceContract]     public interface IService1     {         [OperationContract]         string GetData(int value);         [OperationContract]         CompositeType GetDataUsingDataContract(CompositeType composite);         // TODO: Add your service operations here     }   Client Side:             string mexAddress = http://localhost:53720/Service1.svc?wsdl;                      BasicHttpBinding binding = new BasicHttpBinding();             MetadataExchangeClient MEXClient = new MetadataExchangeClient(binding);             MetadataSet metadata = MEXClient.GetMetadata(new Uri(mexAddress),  MetadataExchangeClientMode.HttpGet);          &nb

SP Output parameter help

  
Hi,I hope someone can help me with sorting this out... I'm trying to build a stored procedure that returns multiple members' names when fed their memberIds.So far this is what I've got - it works fine with one exception - I'm not sure how to write the syntax so I can get the output parameter, @MemberNames? The code below outputs the names but without a column heading. I just want the names to be a string in the output parameter @MemberNamesCREATE PROCEDURE [dbo].[sp_NameResolution] --Add the parameters for the stored procedure here @ProfileId numeric, @MemberIds varchar(8000), -- this might be a string of ids numbers like 34,56,345 @MemberNames varchar(8000) Output, @SQL AS Varchar(8000) = NULL AS BEGIN SET NOCOUNT ON; SET @SQL = 'SELECT (RTRIM(Fname) + '' '' + RTRIM(Lname)) FROM MEMBERS WHERE (MemberIds IN (' + @MemberIds + ')) AND (ProfileID = '+ CAST(@ProfileId AS VarChar)+ ')' PRINT @SQL EXEC(@SQL) END I've tried different variations like..SELECT @MemberNames = (RTRIM(Fname) + '' '' + RTRIM(Lname)) ... etcbut because I'm executing it using EXEC(@SQL) it has a cow and won't output the parameter...Any ideas?Thanks a bunch,Jason

Rounding problem for money output parameter from stored proc

  
I have a GridView sourced by a SQL Server stored procedure with several databound fields, including a money column for item values. My stored proc returns the data through a SELECT and everything looks good. The stored proc also has a single output parameter that sums the total value of the displayed data, and this value is displayed in a label above the GridView. The output parameter (defined as money on the SQL Server side) is passed back to the app in good shape, but is rounded when displayed in the DataSource_Selected event handler. So a total of $30,155.22 in SQL Server shows up as $30155 on my aspx.In debugging, I have confirmed that the value leaving SQL Server is correct (30155.2200), and I can see that the value coming IN to the ASP-side event handler is already rounded. What do I need to do here to coerce/force it to show as money/currency?Relevant snippets:Stored Proc:... @onHandValue money OUT...  CREATE TABLE #tempValueOnHand(... valueOnHand money )... set @onHandValue = (select round(sum(valueOnHand), 2) from #tempValueOnHand) set @onHandValue = (select sum(valueOnHand) from #tempValueOnHand)And again, the output parameter @onHandValue is coming back, just already rounded.On the ASP side:    Protected Sub SqlDataSource1_Selected(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) Handles SqlDataSourc

record count in sqldatasource

  
Hi,   I would like to know how many records are selected in sqldatasource after select command   Thanks

Exposing data contract without passing as input or output parameter for any operation contract

  

I have a method in  wcf which returns stream of custom object. I need to deserialize this stream at client side, but my custom class which is exposed as data contract is not visible through client proxy. When I add a dummy operation contract which returns the custome object I am able to get this custom class. I dont want to write this dummy method as there are many such custom classes.

Is there any way to expose data contract without writing any operation contract that returns or accepts data contract type object?

Example:

[

 

ServiceContract]

Exposing data contract without passing as input or output parameter for any operation contract

  

I have a method in  wcf which returns stream of custom object. I need to deserialize this stream at client side, but my custom class which is exposed as data contract is not visible through client proxy. When I add a dummy operation contract which returns the custome object I am able to get this custom class. I dont want to write this dummy method as there are many such custom classes.

Is there any way to expose data contract without writing any operation contract that returns or accepts data contract type object?


DataBase maximum table record count

  

Hello Friends,

My requirement is, we have more than 5 database servers, each server lot of databases, each database lot of tables.

 I want show the details

---------------------------------------------------------------

ServerName: abcServer

DatabaseName: xyzDatabase

MaximumRecordsTableName: empTable

-----------------------------------------------------------------

In asp or Classic asp.

please anybody help for code and query.

and

how to split the connection string in asp ?






record count for subquery which is used for INSERT

  
My current code is like this

Insert into ReportDetail( Partcipantid, Reportid)

      select distinct ParticipantID , 3 from abc   where

        closed = 0 and ( isnull ( primaryphone, '' )

How to get group count and total count using one select statement?

  

How to obtain the resultset using one select statement?

 

Table 1

CustId

OrderId

A

1000

A

1001

Function with output parameter

  

Hi

is it possible to create user define function with 3 output parameter. something like ref out parameter in C#.

Best Regards. Morteza

 


SSIS audit column Get date and total count of row

  

HI

I have one task in which i have to transfer data from sql to flat file  also i need one more flat file in which i have Number of Row and Getdate

I use multicast column  and then agreegate to count row  i do not know How to achive getdate in this.

 

 


sql count record problem

  

if i have a prodcut with product no. and each product is made by many parts with parts no.
now i would like to retrieve data to count how many parts to make a product.
in sql, can i count parts no. by each product no. like belows:

select product_no,parts_name,manufacture_date,(select count(*) from item where product_no=p.product_no) as [No. of items] from prodcut p left outer join item i on p.product_no=i.product_no

but i found that the execution time is too long, is it the right way to count no. of item in each product??


Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend