SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Add dynamic sql to report...


Add dynamic sql to report...

Author
Message
sql_jr
sql_jr
Right there with Babe
Right there with Babe (776 reputation)Right there with Babe (776 reputation)Right there with Babe (776 reputation)Right there with Babe (776 reputation)Right there with Babe (776 reputation)Right there with Babe (776 reputation)Right there with Babe (776 reputation)Right there with Babe (776 reputation)

Group: General Forum Members
Points: 776 Visits: 161
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!
THE-LIP
THE-LIP
SSC Veteran
SSC Veteran (265 reputation)SSC Veteran (265 reputation)SSC Veteran (265 reputation)SSC Veteran (265 reputation)SSC Veteran (265 reputation)SSC Veteran (265 reputation)SSC Veteran (265 reputation)SSC Veteran (265 reputation)

Group: General Forum Members
Points: 265 Visits: 30
Check the attachment
Attachments
Solutions.JPG (23 views, 26.00 KB)
sql_jr
sql_jr
Right there with Babe
Right there with Babe (776 reputation)Right there with Babe (776 reputation)Right there with Babe (776 reputation)Right there with Babe (776 reputation)Right there with Babe (776 reputation)Right there with Babe (776 reputation)Right there with Babe (776 reputation)Right there with Babe (776 reputation)

Group: General Forum Members
Points: 776 Visits: 161
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
Lynn Pettis
Lynn Pettis
SSC Guru
SSC Guru (225K reputation)SSC Guru (225K reputation)SSC Guru (225K reputation)SSC Guru (225K reputation)SSC Guru (225K reputation)SSC Guru (225K reputation)SSC Guru (225K reputation)SSC Guru (225K reputation)

Group: General Forum Members
Points: 225676 Visits: 40422
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.

Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
RSP
RSP
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1102 Visits: 623
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



Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search