Add dynamic sql to report...

  • Hi,

    Need a little advice on a report I'm trying to finish up. I would like to add a parameter where based on the dropdown selection, to add an "AND" operator to the Where clause. I will give an example.

    Type

    Choice 1 "xid=1"

    Choice 2 "xid=2 AND jtype=123"

    Choice 3 "xid=4 AND jtype=456"

    I tried to add them as available values to a Parameter @Type, but doesn't seem to work, or I don't have the right expression. Or maybe I need a variable?

    So, I would put in the main source query Where this=that AND @Type

    How is the above possible. Please give steps. THanks in advance for your help!

  • Check the attachment

  • Hi, thx for your reply.

    What I want was that @Type would be only 1 parameter, and all the selected values/choices would be part of @Type.

    @Type=A or B or C

    A= AND xid=3

    B= AND xid=4

    C= AND xid=2 and jid=3

    Does this make sense. Thx

  • Nope. Not much here to work with, anything you get will be simple shots in the dark.

    Can you post the code you are working with along with the any other pertenant info, like DDL for the tables, sample data, expected results?

    You may also want to take a little time and read the first article I reference below in my signature block. It walks you through what you need to post and how to post it to get the best possible answers in return.

  • It is a little confusing what you're asking for, but based on your topic title ("adding dynamic sql") and looks like you are trying to build a dynamic where clause. Perhaps try something like this:

    AND (@xid='A' AND value= 1)

    OR (@xid='B' AND value = 2)

    OR (@xid='C' AND value = 3

    AND (@jid = 100)))

    For each parameter that evaluates as true, it will evaluate the other half of the AND statement. So, if 'A' is chosen the value will be 1, etc.

    HTH

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

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