Link to home
Start Free TrialLog in
Avatar of BOEING39
BOEING39

asked on

MARKUP PAGE SELECT STATEMENT

Please see the attached Select Statement from a markup page with a date range selection calendars.    My issue is when I select the date range and run the GridView query it is not restricting the range to those dates selected.   It is returning all the data meeting the parameter restrictions.

 SelectCommand="SELECT [ID], [AOSdate], [Ship], [History], [Sta], [Reason1], [Updated], [Created] FROM [AOS] WHERE (([AOSdate] >= @AOSdate) AND ([AOSdate] <= @AOSdate2) AND ([History] = @History) OR ([History] = @History2)) ORDER BY [History], [AOSdate] DESC">


<SelectParameters>
                            <asp:ControlParameter ControlID="txtstart" Name="AOSdate" PropertyName="Text" Type="DateTime" />
                            <asp:ControlParameter ControlID="txtend" Name="AOSdate2" PropertyName="Text" Type="DateTime" />
                            <asp:Parameter DefaultValue="AOG" Name="History" Type="String" />
                            <asp:Parameter DefaultValue="ETR - Update Required" Name="History2" Type="String" />
                        </SelectParameters>
Avatar of Rainer Jeschor
Rainer Jeschor
Flag of Germany image

Hi,
without seeing the raw data, I assume your query will return everything from the condition:
([History] = @History2)

You might try to use this:
SelectCommand="SELECT [ID], [AOSdate], [Ship], [History], [Sta], [Reason1], [Updated], [Created] FROM [AOS] WHERE (([AOSdate] &gt;= @AOSdate) AND ([AOSdate] &lt;= @AOSdate2) AND (([History] = @History) OR ([History] = @History2))) ORDER BY [History], [AOSdate] DESC"

Open in new window

by encapsulating
([History] = @History) OR ([History] = @History2)
in parentheses so that both together are part of the surrounding AND filter.

HTH
Rainer
Avatar of BOEING39
BOEING39

ASKER

Here is what I have; however, it is still rendering everything as you indicated.

SelectCommand="SELECT [ID], [AOSdate], [Ship], [History], [Sta], [Reason1], [Updated], [Created] FROM [AOS] WHERE (([AOSdate] &gt;= @AOSdate) AND ([AOSdate] &lt;= @AOSdate2) OR (([History] = @History) OR ([History] = @History2))) ORDER BY [History], [AOSdate] DESC"
Hi,
I am on mobile therefore hard to paste code but please change the first OR in your select statement to an AND
Tried No Help.
try the below one

SelectCommand="SELECT [ID], [AOSdate], [Ship], [History], [Sta], [Reason1], [Updated], [Created] FROM [AOS] WHERE
((([AOSdate] &gt;= @AOSdate) AND ([AOSdate] &lt;= @AOSdate2)) OR (([History] = @History) OR ([History] = @History2))
) ORDER BY [History], [AOSdate] DESC"
ASKER CERTIFIED SOLUTION
Avatar of Rainer Jeschor
Rainer Jeschor
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry it took so long to get back with you.    That tool care of the issue.   I had an extra bracket in the code.


Again thanks for your assistance.