none
Doubt in Sql Query on Stored Procedure RRS feed

  • Question

  • Hi Friends,

                 

    In my project i want to filter total amount by FromDate and ToDate. and my doubt was i want to filter same amount <15 DifferenceDate , < 30 DifferenceDate....... <90 DifferenceDate

    Ex: 

    Total Amount    Date1   Date2  DifferenceDate    amount < 30    amount <60

    20000 01/01/2013 01/02/2013        60           10000(mu assumption) 20000(mu assumption)

    here < 30 is 30 days less than difference date or 30 days less than Date2 

    < 60 is 60 days is less than differencdate date or  greater than 30 and less than 60days

    Please i need your help. i am in big head ache:) please send me Sql Query for this Doubt. post here or send to my mail id dinesh6690@gmail.com.. please send as soon as possible. thanks in advance . i have attached the sample


    .NET


    Wednesday, January 8, 2014 1:22 PM

Answers

All replies

  • Is this visual Studio (C# or vbnet) or Excel VBA?

                    string connStr = "Enter Your connection string here";
                    SqlConnection conn = new SqlConnection(connStr);
                    DateTime today = DateTime.Today;
                    DateTime thirtyDays = today.AddDays(-30);
                    string SQL = "Select * from table1 where date between @startDate and @endDate";
                    SqlCommand cmd = new SqlCommand();
                    cmd.Parameters.Add("@startDate", SqlDbType.DateTime);
                    cmd.Parameters.Add("@endDate", SqlDbType.DateTime);
                    cmd.Parameters["startDate"].Value = thirtyDays;
                    cmd.Parameters["endDate"].Value = today;
                    SqlDataAdapter adapter = new SqlDataAdapter(SQL, conn);


    jdweng

    • Proposed as answer by Naomi N Wednesday, January 8, 2014 10:09 PM
    Wednesday, January 8, 2014 2:25 PM
  • i am sorry sir.. i want back end coding. i.e we are filtering using stored procedure, so i want to write in sp. kindly do me the favour

    .NET


    Wednesday, January 8, 2014 5:38 PM
  • i am sorry sir.. i want back end coding. i.e we are filtering using stored procedure, so i want to write in sp. kindly do me the favour

    .NET

    Wednesday, January 8, 2014 5:39 PM
  • Try the TSQL forum, and post your table DDL, sample data and expected results.

    David


    David http://blogs.msdn.com/b/dbrowne/

    Wednesday, January 8, 2014 5:46 PM