Pass parameters to SQL DataSource RRS feed

  • Question

  • User-604655155 posted


     I know that there is many thread like my but I didn't find answer for my question.

    I have complex query in select command in SQL Data Source. I call few tables.

    e.i. select * from TableA
         join TableB
         join TableC

    I would like to manage where clause. Sometimes I will filter by field in TableC, sometime by field in TableA.


    e.i: 1
    TableB.Field1 = @parm1

    e.i: 2
    TableC.Field1 = @parm2

    In one time I get value only for one paramater. I haven't where clause like this TableB.Field1 = @parm1 AND TableC.Field1 = @parm2

    Is there function to add field in where clause dynamically or I can set to @parm1 value "unlimited" and SQL DataSource ignore this parm during executing?

    I can write few SQL command depend on parm value but I'm looking for better solution.

    (I use .net 2.0)

    Monday, July 22, 2013 5:55 AM


  • User503812343 posted

    You can use OR clause 

    TableB.Field1 = @parm1 OR TableC.Field1 = @parm2

    Or you can use dynamic query. Build your query in one varchar variable and execute it

    declare @sql varchar(max)

    set @sql = "your query"


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 24, 2013 10:40 AM