Link to home
Start Free TrialLog in
Avatar of directxBOB
directxBOBFlag for Ireland

asked on

Help with a where statement

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

Avatar of Rahul Goel
Rahul Goel
Flag of India image

Your question is so confusing. Can you please give me some live example or make it so clear to me?
Thank you
Avatar of directxBOB

ASKER

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

ASKER CERTIFIED SOLUTION
Avatar of diazluna
diazluna
Flag of United States of America 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