none
Visual Studio Data Set with Dynamic Where Clause

    Question

  • I have created at VB.Net application using Visual Studio 2015.  I have added a DataSet to my application and wanted to know if there was a way to create a dynamic Where clause in My Select Statement?  Below is my CURRENT Select Statement.  I want to Know that Can I have a Parameter From my Application determine which field to use in my Where Clause?  Example, If the Parameter Returns a value of 1 Then "Where UseForMaint = 1"  If the Parameter Returns a value of 0 Then "Where UseForWhse = 1".  The Parameter value determines WHICH field to use in the Where Clause.  I hope that this makes sense? Thank you in advance for your assistance.

    SELECT        AttendCode, AttendanceCodeDesc, AutoNum, CodeColor, UpdatedBy, UpdateDate, PointValue, MultiDate, SpecialPermission, IsVisible, Comments, UseForAttendance,
                              UseForWhse, UseForMaint, WhsePointValue, MaintPointValue, UseForAttend_Leave
    FROM            AttendanceCodes
    ORDER BY AttendanceCodeDesc


    Paul

    Saturday, April 22, 2017 6:51 PM

Answers

  • Maybe try this:

       WHERE (@Parameter=1 AND UseForMaint = 1) OR (@Parameter=0 AND UseForWhse = 1)


    • Edited by Viorel_MVP Saturday, April 22, 2017 7:12 PM
    • Marked as answer by Paul 2 U Saturday, April 22, 2017 7:24 PM
    Saturday, April 22, 2017 7:11 PM

All replies

  • Maybe try this:

       WHERE (@Parameter=1 AND UseForMaint = 1) OR (@Parameter=0 AND UseForWhse = 1)


    • Edited by Viorel_MVP Saturday, April 22, 2017 7:12 PM
    • Marked as answer by Paul 2 U Saturday, April 22, 2017 7:24 PM
    Saturday, April 22, 2017 7:11 PM
  • Thank you so much.  This is exactly what i was looking for.  Works Great.


    Paul

    Saturday, April 22, 2017 7:24 PM