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>
BOEING39Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rainer JeschorCommented:
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
0
BOEING39Author Commented:
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"
0
Rainer JeschorCommented:
Hi,
I am on mobile therefore hard to paste code but please change the first OR in your select statement to an AND
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

BOEING39Author Commented:
Tried No Help.
0
Jitendra PatilSr.Software EngineerCommented:
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"
0
Rainer JeschorCommented:
Hi,

again, the following returns all where the date is between the two parameters AND the history is either one of the two parameters:

Formatted:
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

Open in new window

Code style:
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"

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BOEING39Author Commented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.