Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Help with a where statement

Posted on 2009-07-06
3
187 Views
Last Modified: 2012-05-07
I am creating an ASP Application and have the following SQL Statement:

select assetname, serialnumber,parentserialnumber,(case when parentserialnumber = '' then 'False' else 'True' end) as assigned
from assets
where parentserialnumber like @asset

So what I have is a drop down box that allows the user to select:

Both
Assigned
Un-Assigned

The problem I am having is how to structure my SQL so that I can take advantage of the 3 possible states. Both would simply be a '%' while Un-Assigned would be ''

But how would I go about getting the Assigned Values, as I am not sure  how I could tweak my SQL statement to allow this.

Cheers
<asp:DropDownList ID="ddlAssigned" runat="server" AppendDataBoundItems="True" 
                            AutoPostBack="true" Width="150px">
                            <asp:ListItem Value="-1">All</asp:ListItem>
                            <asp:ListItem Value="1">Assigned</asp:ListItem>
                            <asp:ListItem Value="2">Un-Assigned</asp:ListItem>
                        </asp:DropDownList>
 
 
//in the code behind   
 
 
 
 Protected Sub SqlDataSource1_Selecting(ByVal sender As Object, ByVal e As SqlDataSourceSelectingEventArgs)
 
       If ddlAssigned.SelectedValue.Equals("1") Then
            e.Command.Parameters("@assigned").Value = ""
        ElseIf ddlAssigned.SelectedValue.Equals("2") Then
            e.Command.Parameters("@assigned").Value = ""
        End If
    End Sub

Open in new window

0
Comment
Question by:directxBOB
3 Comments
 
LVL 9

Expert Comment

by:Rahul Goel ITIL
ID: 24783593
Your question is so confusing. Can you please give me some live example or make it so clear to me?
Thank you
0
 

Author Comment

by:directxBOB
ID: 24783701
I have this SQL Statement

select assetname, serialnumber,parentserialnumber,(case when parentserialnumber = '' then 'False' else 'True' end) as assigned
from assets
where parentserialnumber like @asset

the @asset is an SQLDatasource Parameter, where I am going to inject data into the statement to get the desired results.

I am looking to adapt the SQL statement so that I can get the desired results depending on the state I am selecting:

Both
Assigned
Un-Assigned

0
 
LVL 2

Accepted Solution

by:
diazluna earned 500 total points
ID: 24816958
The trick is in the Values you are passing plus your like statement.

if dropdown = "Both" then
    Param1 = "Assigned"
    Param2 = "Un-Assigned"
else
    Param1 = dropdown.value
    Param2 = ""
end if
 
//And then your query:
select assetname, serialnumber,parentserialnumber,(case when parentserialnumber = '' then 'False' else 'True' end) as assigned
from assets
where parentserialnumber = @asset1
   or parentserialnumber = @asset2
 
//Finally assigne @asset1 and @asset2 your values from parameter1 and parameter2.

Open in new window

0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question