How to get sorted data wihin the region date from and dateto
i have to text boxes textbox1 in which user enter from date and in textbox2 user enetr to date and after button clickevent the gridview will display the record between fromdate and to date..how to write procedure in sql2005?how to write code and where i have to write?datatype is datetime,i am not inserting DateFrom and DateTo in table,,jest select using by datetime picker.i have only one column in table that is 'drpdate'.

Iftikar HussainRank #423 · 5.9K reputationPosted Jul 15, 2013, 11:07 PM EDT
You need to pass from and to date to your stored procedure. And write the query like this
@StartDate and @EndDate are input parametrs of datetime for your SP
SELECT
col1,col2...
FROM
table1
WHERE
CreatedOn>=@StartDate and CreatedOn<=@EndDate
Regards,
Iftikar
MANEESH AN110 reputationPosted Jul 16, 2013, 12:20 AM EDT
(
@DTFROM datetime,
@DTTO datetime
)
AS
BEGIN
SELECT
ACC.dRPDate DATE,
ACC.cVType TYPE,
TS.vSeries SERIES,
ACC.iRPNo VOUCHERNO,
ACM.vAcName HEAD,
ACC.vNarration NARRATION,
ACC.deDRAmount DEBIT,
ACC.deCRAmount CREDIT
FROM tbl_Acc_Voucher AS ACC INNER JOIN
tblSerialNumbers AS TS ON ACC.iSeriesId = TS.iSeriesId INNER JOIN
tbl_Acc_AccountMaster AS ACM ON ACM.iAcID = ACC.iAcID
where dRPDate >=@DTFROM and dRPDate<=@DTTO
END
DLL
public DataTable fnPayRegDateView(string strWhereCondition)
{
Connection objCon = new Connection();
SqlParameter[] parmsDetails = new SqlParameter[1];
parmsDetails[0] = new SqlParameter();
parmsDetails[0].SqlDbType = SqlDbType.VarChar;
parmsDetails[0].Value = strWhereCondition;
parmsDetails[0].ParameterName = "@WhereCondition";
DataTable dt = new DataTable();
dt = objCon.fnSelectData("sp_PaymentRegisterGridView", parmsDetails);
return dt;
}
IS THIS CORRECT OR NOT?I THINK STRING STRWHERECONDITION IS WRONG?
MANEESH AN110 reputationPosted Jul 16, 2013, 12:56 AM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 16, 2013, 12:58 AM EDT
Regards,
Iftikar
MANEESH AN110 reputationPosted Jul 16, 2013, 1:03 AM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 16, 2013, 1:08 AM EDT
Regards,
Iftikar
Ravi ShekharRank #673 · 3.6K reputationPosted Jul 16, 2013, 2:21 AM EDT
In which format your column is in sql table.
Ravi ShekharRank #673 · 3.6K reputationPosted Jul 16, 2013, 2:43 AM EDT
if your sql column is in varchar format .please first convert into proper datetime format...
try below query...
SELECT * from table where
convert(DATETIME,CreatedDate,101)>=convert(DATETIME,@From,101)
AND
convert(DATETIME,CreatedDate,101) <= convert(DATETIME,@To,101)
Mark it as answer if it helped .
MANEESH AN110 reputationPosted Jul 16, 2013, 3:13 AM EDT
Ravi ShekharRank #673 · 3.6K reputationPosted Jul 16, 2013, 3:33 AM EDT
SELECT * from table where
convert(DATETIME,CreatedDate,101)>=convert(DATETIME,@From,101)
AND
convert(DATETIME,CreatedDate,101) <= convert(DATETIME,@To,101)
MANEESH AN110 reputationPosted Jul 16, 2013, 3:40 AM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 16, 2013, 3:48 AM EDT
Regards,
Iftikar
Ravi ShekharRank #673 · 3.6K reputationPosted Jul 16, 2013, 3:49 AM EDT
and Use this SP
ALTER PROCEDURE [dbo].[sp_PaymentRegisterGrid]
(
@DTFROM datetime,
@DTTO datetime
)
AS
BEGIN
SELECT
ACC.dRPDate DATE,
ACC.cVType TYPE,
TS.vSeries SERIES,
ACC.iRPNo VOUCHERNO,
ACM.vAcName HEAD,
ACC.vNarration NARRATION,
ACC.deDRAmount DEBIT,
ACC.deCRAmount CREDIT
FROM tbl_Acc_Voucher AS ACC INNER JOIN
tblSerialNumbers AS TS ON ACC.iSeriesId = TS.iSeriesId INNER JOIN
tbl_Acc_AccountMaster AS ACM ON ACM.iAcID = ACC.iAcID
where
convert(DATETIME,dRPDate ,101)>=convert(DATETIME,@DTFROM ,101)
AND
convert(DATETIME,dRPDate ,101) <= convert(DATETIME,@DTTO,101)
END
MANEESH AN110 reputationPosted Jul 16, 2013, 4:32 AM EDT
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 16, 2013, 4:37 AM EDT
cn is your connection string. if you store your connection string in different variable pass it their.
MANEESH AN110 reputationPosted Jul 16, 2013, 4:44 AM EDT
in this which variable should use for "cn"?
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 16, 2013, 4:46 AM EDT
MANEESH AN110 reputationPosted Jul 16, 2013, 4:52 AM EDT
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 16, 2013, 7:45 AM EDT
1st add the reference of
using System.Configuration;
public DataTable GET_PRE_SALES_REPORT(string From, string To)
{
string cn= ConfigurationManager.ConnectionStrings["MagnaDBConnection"].ConnectionString;
adap = new SqlDataAdapter("sp_PaymentRegisterGrid", cn);
adap.SelectCommand.CommandType = CommandType.StoredProcedure;
adap.SelectCommand.Parameters.AddWithValue("@from", From);
adap.SelectCommand.Parameters.AddWithValue("@to", To);
dt = new DataTable();
adap.Fill(dt);
return dt;
}
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 16, 2013, 7:45 AM EDT
in your code
Regards,
Iftikar