sql server - Get all records in SQL depending on user input -
i learning sql , came across difficulty. data table looks this
dbo data
id | name | surname | title | location ---------------------------------------- 1 | xxx | abc | def | london 2 | xxx | abc | def | oslo 3 | xxx | abc | def | new york
now want id, name, title , surname , use query this:
select id, name, surname, title data location = 'london' -- (this user input)
but problem if user inputs all
or world
or empty string in where
clause, want query return rows. possible writing query handle special scenarios above????
i using asp.net datasource
<asp:sqldatasource id="sqldatasource1" runat="server" connectionstring="<%$ connectionstrings:mainconnectionstring %>" selectcommand="select [name], [id], [surname], [title] [data] [location] = @location)" > <selectparameters> <asp:controlparameter controlid="label1" name="location" propertyname="text" type="string" /> </selectparameters> </asp:sqldatasource>`
the input depends on route path of url localhost:56789/people/london/
the corresponding vb file
protected sub page_load(sender object, e eventargs) handles me.load if (request.pathinfo.length = 0) else dim t = request.pathinfo.substring(1) label1.text = t end if end sub
i know can application side curios if possible in query itself.
if want in query, try this:
select id, name, surname, tittle data location = <input> or <input> in ('all', 'world', '')
Comments
Post a Comment