Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Sql query help

LEGEND ,
Nov 05, 2006 Nov 05, 2006
I have a question regarding a sql query I hope somebody can help me with.

I have the select command below. I want to pass a query string from a link
like news.aspx?field1=TRUE. My problem is that if an entry in the database
includes TRUE setting for multiple fields I do not get all the entries with
the sql query only those where only field1 is TRUE. So basically I want to
retrive all entries from the database where field1=True including those
where either field2 or field3 also maybe True. Can anyone help?

<asp:SqlDataSource ID="newsindex" runat="server" ConnectionString="<%$
ConnectionStrings:newsConnectionString %>"
ProviderName="<%$
ConnectionStrings:newsConnectionString.ProviderName %>"
SelectCommand="SELECT [aDate], [Titel], [Short], [Pic], [field1],
[field2], [field3], [ArticleID] FROM [artikler] WHERE (([dvbs] = ?) AND
([dvbc] = ?) AND ([dvbt] = ?)) ORDER BY [aDate] DESC">
<SelectParameters>
<asp:QueryStringParameter DefaultValue="FALSE" Name="field1"
QueryStringField="field1"
Type="Boolean" />
<asp:QueryStringParameter DefaultValue="FALSE" Name="field2"
QueryStringField="field2"
Type="Boolean" />
<asp:QueryStringParameter DefaultValue="FALSE" Name="field3"
QueryStringField="field3"
Type="Boolean" />
</SelectParameters>
</asp:SqlDataSource>



TOPICS
Server side applications
251
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 05, 2006 Nov 05, 2006
Your current statement uses AND to link all the fields together hence your
problem. Just change it to OR in the SQL statement

--
Paul Whitham
Certified Dreamweaver MX2004 Professional
Adobe Community Expert - Dreamweaver

Valleybiz Internet Design
www.valleybiz.net

"Bob" <no@mail.com> wrote in message
news:eikvso$5m6$1@forums.macromedia.com...
> I have a question regarding a sql query I hope somebody can help me with.
>
> I have the select command below. I want to pass a query string from a link
> like news.aspx?field1=TRUE. My problem is that if an entry in the database
> includes TRUE setting for multiple fields I do not get all the entries
> with the sql query only those where only field1 is TRUE. So basically I
> want to retrive all entries from the database where field1=True including
> those where either field2 or field3 also maybe True. Can anyone help?
>
> <asp:SqlDataSource ID="newsindex" runat="server" ConnectionString="<%$
> ConnectionStrings:newsConnectionString %>"
> ProviderName="<%$
> ConnectionStrings:newsConnectionString.ProviderName %>"
> SelectCommand="SELECT [aDate], [Titel], [Short], [Pic], [field1],
> [field2], [field3], [ArticleID] FROM [artikler] WHERE (([dvbs] = ?) AND
> ([dvbc] = ?) AND ([dvbt] = ?)) ORDER BY [aDate] DESC">
> <SelectParameters>
> <asp:QueryStringParameter DefaultValue="FALSE" Name="field1"
> QueryStringField="field1"
> Type="Boolean" />
> <asp:QueryStringParameter DefaultValue="FALSE" Name="field2"
> QueryStringField="field2"
> Type="Boolean" />
> <asp:QueryStringParameter DefaultValue="FALSE" Name="field3"
> QueryStringField="field3"
> Type="Boolean" />
> </SelectParameters>
> </asp:SqlDataSource>
>
>
>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 05, 2006 Nov 05, 2006
Paul Whitham AdobeCommunityExpert wrote:
> Your current statement uses AND to link all the fields together hence
> your problem. Just change it to OR in the SQL statement

Actually AND is what I wanted.

I figured it out. I needed to set ConvertEmptyStringToNull value.


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 05, 2006 Nov 05, 2006
LATEST
Thank you for your reply.

I did get code below to work inside Test Query in Visual Web Developer. If I
set the [dvbs] field to True and no default value for the parameters is set,
it returns [dvbs] True items just like I want. But if I set up an url with
a querystring like <A href="newsindex.aspx?dvbs=TRUE"> no data is returned.
How do I accomplish the same result from an url like I can get with Test
Query in Visual Web Developer?

<asp:SqlDataSource ID="nyhedsindex" runat="server" ConnectionString="<%$
ConnectionStrings:nyhederConnectionString %>"
ProviderName="<%$
ConnectionStrings:nyhederConnectionString.ProviderName %>"
SelectCommand="SELECT [Dato], [Titel], [Resume], [Pic], [dvbs],
[dvbc], [dvbt], [hdtv], [iptv], [tvnyt], [ArticleID] FROM [artikler] WHERE
(([dvbs] = ?) OR ([dvbc] = ?) OR ([dvbt] = ?) OR ([hdtv] = ?) OR ([iptv] =
?) OR ([tvnyt] = ?)) ORDER BY [Dato] DESC">
<SelectParameters>
<asp:QueryStringParameter Name="dvbs" QueryStringField="dvbs"
Type="Boolean" />
<asp:QueryStringParameter Name="dvbc" QueryStringField="dvbc"
Type="Boolean" />
<asp:QueryStringParameter Name="dvbt" QueryStringField="dvbt"
Type="Boolean" />
<asp:QueryStringParameter Name="hdtv" QueryStringField="hdtv"
Type="Boolean" />
<asp:QueryStringParameter Name="iptv" QueryStringField="iptv"
Type="Boolean" />
<asp:QueryStringParameter Name="tvnyt" QueryStringField="tvnyt"
Type="Boolean" />
</SelectParameters>
</asp:SqlDataSource>

Paul Whitham AdobeCommunityExpert wrote:
> Your current statement uses AND to link all the fields together hence
> your problem. Just change it to OR in the SQL statement






Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines