Skip to content
Loading
SQL Query - Please Help
  • Nitin Sontakke
    I am hoping that another question asked by you is not related to the original question.
     
    If yes, there are couple of ways to go around it and I try my best not to use output parameters at all.
     
    1/ In the stored procedure, just select both the variables as:
     
    select @minDateOut [MinDate], @maxDateOut [MaxDate]
     
    and use execute reader in C# and you will get just one record with two columns.
     
    2/ Another way is to combine two strings as:
     
    select @minDateOut + '|' + @maxDateOut [ReturnValue]
     
    and use execute scalar in C# and you will get just one string which is pipe separated. Just split it and you will get two dates in an array. Simple.
    0
  • One more query - How to get minimum and maximum date in output variable (varchar(max)) from stored procedure to asp.net c# ?
    My Stored Procedure -
    @MinDateOut varchar(max) output ,
    @MaxDateOut varchar(max) output
    Select @MinDateOut = convert(min(t.CreatedOn),106) from UserTransactions t
    Select @MaxDateOut = convert( max(t.CreatedOn), 106) from UserTransactions t
    CS File-
    SQLParamenter MinDate = cmd.Parameters.Addwithvalue("@MinDateOut",SQLDBType.varchar);
    MinDate.Direction = Output;
    ----------
    Error - Error converting datatype string to int
    ---
    Please guide..
     
    I also tried -
     
    set @Mindateout = ( select convert(varchar(max), min(t.CertifiedOn),106) from UserTransactions t )

    set @MaxDateout = (select convert(varchar(max), max(t.CertifiedOn),106) from UserTransactions t ) 
     
    ---
    Error -
    Source = ".Net SqlClient Data Provider"
    Message = "Error converting data type varchar(max) to int."
     
    Please guide ... its a bit urgent... Thanks in advance...
    0
  • Bikesh Srivastava
    Yes manas answer is corrcet.
    0
  • Manas Mohapatra
    Try like this:
    1. SELECT um.UserName, COUNT(ut.ID) TotalTran,  
    2. CASE  
    3. WHEN COUNT(ut.ID) > 0 THEN 'TRUE'  
    4. ELSE 'FALSE',  
    5. MAX(ut.Certifiedon) as [Date]  
    6. FROM UserMaster um  
    7. INNER JOIN UserTransactions ut  
    8. ON um.UserName = ut.UserName  
    9. GROUP BY um.UserName  
     
    +3