Create a dynamic query

  • I want to create a dynamic query but how can I do it with the clause WHERE , so I can filtratate from different filelds.

  • Nav - I think you will get more accurate/useful/quick answers if you post an example.

    Post an example table structure, some example data for it, some example inputs, and what results you want from the query at the end...

    Here's some reading material for you too...

    http://www.sommarskog.se/dyn-search.html

    http://www.sommarskog.se/dynamic_sql.html

    Ryan Randall

    Solutions are easy. Understanding the problem, now, that's the hard part.

  • can you provide example??

     

    BTW check this out. if it works for you

    BEGIN

    DECLARE @Col varchar(20)

    DECLARE @val varchar(20)

    SET @col='ABC'

    SET @val='XYZ'

    exec ('SELECT * FROM SUBJECT WHERE '  + @Col + ' = ''' + @val +'''' + ' order by ' + @col)

    END

  • Hey Ryan, I guess that the example (links) are good, and of course I think can help me with the problem, many thanks man, see you later... 

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply