Showing posts with label parameters. Show all posts
Showing posts with label parameters. Show all posts

Wednesday, March 28, 2012

how to asssign string variable to SqlDbType

i have string variable as,

String str="Int";

now, while assigning sql parameters, i want

param.SqlDBType=SqlDBType.Int;

but, value of Int is dynamic. it may be string or double so,

i want it to be as,

param.SqlDBType=(SqlDBType)str;

but its not acceptable(its invalid cast).

in any way can i do it and how?

regards--

The SqlDBType is not the value you are passing to the database, rather it is the data type. Therefore this must match that of your table column data type.

If your column is a varchar you would assign SqlDBType.Varchar or of it is an Int you would assign SqlDBType.Int.

To assign the actual value to the parameter you use the Value property.

e.g. param.Value = <the value you want to assign to the parameter>

Wednesday, March 21, 2012

How to allow apostrophes in string parameters

I have a few reports that contain a customer name parameter. I have
just realized that when a customer name contains a single-quote
(apostrophe), reporting services thinks that it's an unclosed string
and I receive an error.
The error I get -
"An error has occurred during report processing.
Query execution failed for data set '....'.
Line 1: Incorrect syntax near 's'.
Unclosed quotation mark before the character string"."
I know that I probably need to 'escape' the single quote, but I am
unclear if I can do this on the data tab in report designer or if I
have to do this through my views/stored procs in sql server. After
determining where to make the change, I will also need to know what
the correct syntax is.
Thanks so much for your help.
CrystalOn Feb 14, 11:59=A0am, Just Another Reporter <Crystal.War...@.gmail.com>
wrote:
> I have a few reports that contain a customer name parameter. =A0I have
> just realized that when a customer name contains a single-quote
> (apostrophe), reporting services thinks that it's an unclosed string
> and I receive an error.
> The error I get -
> "An error has occurred during report processing.
> Query execution failed for data set '....'.
> Line 1: Incorrect syntax near 's'.
> Unclosed quotation mark before the character string"."
> I know that I probably need to 'escape' the single quote, but I am
> unclear if I can do this on the data tab in report designer or if I
> have to do this through my views/stored procs in sql server. =A0After
> determining where to make the change, I will also need to know what
> the correct syntax is.
> Thanks so much for your help.
> Crystal
Go to the Data tab, and click the Properties button [...] for the
Dataset. Under the Parameters tab, you will see mappings between the
parameters used in the dataset, mapped to the Report Parameters. Note
that these are expressions, so you can put your own code in here to
"escape" the single quote.
What you will want to do is do is something like:
@.Pararm =3DReplace( Parameters!Param.Value, "'", "''" )
-- Scott

Monday, March 12, 2012

How to add parameters to a MDX query in RS 2005?

I'm currently struggling with parameters when doing reports based on SSAS
2005 in RS 2005.
How do I add a new parameter to an MDX query, after having built the query
using the wysiwig query builder? I could probably start all over again to
use the query builder, but I can't figure out how to create semi-dynamic
queries like I did with RS 2000 / AS 2000.
And is there a way to choose if a parameter should be multivalue when adding
it as a parameter?
Any good books focusing on Reporting Services and Analysis Services 2005?
Most of them focus on SQL based reports.
Kaisa M. Lindahl LervikHope you have tried puting "@." to the parameters this is basics and go to
report parameter from menu and can define multi value.
A book from "Brian Larson" of SSRS and SS BI is good book to start with and
your online help and samples are best resources for learning.
Amarnath
"Kaisa M. Lindahl Lervik" wrote:
> I'm currently struggling with parameters when doing reports based on SSAS
> 2005 in RS 2005.
> How do I add a new parameter to an MDX query, after having built the query
> using the wysiwig query builder? I could probably start all over again to
> use the query builder, but I can't figure out how to create semi-dynamic
> queries like I did with RS 2000 / AS 2000.
> And is there a way to choose if a parameter should be multivalue when adding
> it as a parameter?
> Any good books focusing on Reporting Services and Analysis Services 2005?
> Most of them focus on SQL based reports.
> Kaisa M. Lindahl Lervik
>
>|||I had problems with the whole strtomember syntax. Just making a parameter
didn't put this new parameter into the query, probably because I'd gone from
the editor to hand editing the query, and I couldn't figure out the syntax
of a new parameter.
Anyway, I found out how to make dynamic mdx queries the old way*. I'll check
out the book by Brian Larson, there's probably a more modern way of making
mdx based reports than the old school way I'm used to. ;)
*= Make a new data source with OLE DB instead of Analysis Services, and then
connect it to Analysis Services 9.0. Gives you back the good old text only
editor, which I prefer right now.
Kaisa M: Lindahl Lervik
"Amarnath" <Amarnath@.discussions.microsoft.com> wrote in message
news:FFF7458A-F34C-4CC7-8CA0-55C59B8C0106@.microsoft.com...
> Hope you have tried puting "@." to the parameters this is basics and go to
> report parameter from menu and can define multi value.
> A book from "Brian Larson" of SSRS and SS BI is good book to start with
> and
> your online help and samples are best resources for learning.
> Amarnath
> "Kaisa M. Lindahl Lervik" wrote:
>> I'm currently struggling with parameters when doing reports based on SSAS
>> 2005 in RS 2005.
>> How do I add a new parameter to an MDX query, after having built the
>> query
>> using the wysiwig query builder? I could probably start all over again to
>> use the query builder, but I can't figure out how to create semi-dynamic
>> queries like I did with RS 2000 / AS 2000.
>> And is there a way to choose if a parameter should be multivalue when
>> adding
>> it as a parameter?
>> Any good books focusing on Reporting Services and Analysis Services 2005?
>> Most of them focus on SQL based reports.
>> Kaisa M. Lindahl Lervik
>>

How to add parameters and filters?

Hi,

I would like to ask a few questions about Reporting Services.

1. Can we add new parameters (by code on VS2005) at runtime when the report it's on a server? Since the job of the Report Viewer only allow to get/set parameters and not add new parameter, i wonder if there is a way to add parameter without adding manually on the report design mode.

2. Can i add some filter to change the data show on the report? (To be more specific, I didnt mean to add filter at the design mode on VS2005, I want to be able to add filter by code)

3. Can i change the query (dataset) of a report at runtime (once again i mean by code) which it's on the reportserver? (Since we can change the query on a rdlc report , i wonder if we can do the same on a rdl.)

Thanks in advance

1. No, you can only change the # of parameters by republishing the RDL.

2. No, you can only add filters in the RDL. You can affect the filter by runtime parameters, though.

3. You can change the connection string at runtime via a parameter, but not the query. That would require republishing an updated RDL.

BTW, you can call SetReportDefinition programatically, so you can achieve all your objectives roundabout by crafting an updated RDL and republishing in code or with script.

How to add parameter for file name for subscription

Hi,
I working on Report Delivery by "Report Server File Share".
I like to add parameters into the name.
for example,
report name is "order". there are paremeter name "startdate" and "endate".
I'd like to change the filename "order_startdate_12_1_06_enddate_12_2_06"
something like that.
Is there any way to attach parameters to FileName?
Thanks
KenHi Ken,
I am not sure if you can add a parameter to change the file name at
runtime after you have created the subscription.
I can suggest Data driven subscriptions where you can execute a query
which will return all these parameters to you from the data base. You
can specify a name for the report based on your requirements and this
column can be mapped to the FileName in the subscription which will
create a file witht that name.
If you dont know what a data driven subscription is this will get you
started.
http://msdn2.microsoft.com/en-us/library/ms156012.aspx
Hope this helps,
Virat
Ken wrote:
> Hi,
> I working on Report Delivery by "Report Server File Share".
> I like to add parameters into the name.
> for example,
> report name is "order". there are paremeter name "startdate" and "endate".
> I'd like to change the filename "order_startdate_12_1_06_enddate_12_2_06"
> something like that.
> Is there any way to attach parameters to FileName?
> Thanks
> Ken

How to add Optional Parameters for SQL Reporting Service 2005

Hi friends,

I am developing reports using SQL Server 2005 Reporting service

I want to pass optional parameters to Report using dropdown

I filled dataset using EmpId and EmpName. and assigned this dataset to

query the values.

I checked properties for Report Parameters of Allow Null, Allow Blank values

Even i checked this properties, it enforces me to Enter some value for dropdown while running or previewing the report

I don't want to enforce the user that value must be selected.

In short, How we can able to pass multiple parameters which are not mandatory.

Pls reply me ASAP

Any suggestion is appreciated

Thanks in Advance.

Regards

Suds

hmm.... if i set the parameter to be multivalue, there'll be error if i want to set it to Allow Null...

my solution is if user does not want to select any specific value, then they can use select all....

i don't know how to put select all as the default value... maybe someone can suggest this...

if you found out, pls share ya....

|||Add a default value of "All" and use this value with in your expressions/queries to allow for a catch all situation

eg: with in the sql where clause add the following:
and case @.empid = 'All' then table.emp_id else @.empid = table.emp_id

It is a little bit messy to write but I believe it gives you the most control over the report.

Sam Vella.|||

minority80 wrote:

i don't know how to put select all as the default value... maybe someone can suggest this...

Report -> Parameters
Select the parameter you want to add a default value to
Select the Non-Queried radio Button
Enter "All" without the quotes into the text box

Sam Vella

How to add if ~else to a exist Stored Procedure

here is my original Sql Code

I add a parameters @.CustId in line 13

when CustID not Null, I want to add this to the Where clause line 146 and 156

if CustId not null then where clause will add a reference like CustId = @.CustID

if CustId is Null then not reference @.custID

how to Add a if ~else clause to my code? i tried all day.. but it doesn't work..

1SET QUOTED_IDENTIFIEROFF2GO3SET ANSI_NULLSOFF4GO5678ALTER PROCEDURE [dbo].[usp_OutDataDownQuery]9@.DTBEGDATETIME,10@.DTENDDATETIME,11@.RemarkINT,12@.BankIdVARCHAR (128)13@.CustIDCHAR141516as17181920SELECT21*22FROM23(24SELECT25ZT_Master.PriKey,26ZT_Master.BankId,27ZT_Master.TDateTime,28ZT_Master.PNo,29ZT_Master.Remark,30ZT_Master.CustId,31ZT_Master.ProcStatus,32ZT_Customer.[Name],33--ZT_Customer.AccountBAK AS Account,34--ZT_Customer.SCAccountBAK AS SCAccount35(SELECT TOP 1SUBSTRING(PCLNO, 3, 12)FROM ZT_DetailWHERE ZT_Master.PriKey = ZT_Detail.MasterKeyAND ZT_Detail.TXTYPE ='SD')AS Account,36(SELECT TOP 1SUBSTRING(PCLNO, 3, 12)FROM ZT_DetailWHERE ZT_Master.PriKey = ZT_Detail.MasterKeyAND ZT_Detail.TXTYPE ='SC')AS SCAccount37FROM38ZT_MasterLEFTJOIN ZT_CustomerON ZT_Master.CustId=ZT_Customer.Id39) a40,---------------------------------------------------41(SELECT MasterKey=ISNULL(a.MasterKey,b.MasterKey),42CtcbBanSDTotal=ISNULL(本行代收筆數,0),43CtcbBanSDTotalAMT=ISNULL(本行代收金額,0),44OtherBanSDTotal=ISNULL(他行代收筆數,0),45OtherBanSDTotalAMT=ISNULL(他行代收金額,0),46CtcbBanSCTotal=ISNULL(本行代付筆數,0),47CtcbBanSCTotalAMT=ISNULL(本行代付金額,0),48OtherBanSCTotal=ISNULL(他行代付筆數,0),49OtherBanSCTotalAMT=ISNULL(他行代付金額,0),50GoodSDTotal=ISNULL(代收成功筆數,0),51GoodSDTotalAMT=ISNULL(代收成功金額,0),52GoodSCTotal=ISNULL(代付成功筆數,0),53GoodSCTotalAMT=ISNULL(代付成功金額,0),54BadSDTotal=ISNULL(代收失敗筆數,0),55BadSDTotalAMT=ISNULL(代收失敗金額,0),56BadSCTotal=ISNULL(代付失敗筆數,0),57BadSCTotalAMT=ISNULL(代付失敗金額,0)58FROM (SELECT MasterKey=ISNULL(a.MasterKey,b.MasterKey),59本行代收筆數,60本行代收金額,61他行代收筆數,62他行代收金額,63本行代付筆數,64本行代付金額,65他行代付筆數,66他行代付金額,67代收成功筆數,68代收成功金額,69代付成功筆數,70代付成功金額71FROM (SELECT MasterKey=ISNULL(a.MasterKey,b.MasterKey),72本行代收筆數,73本行代收金額,74他行代收筆數,75他行代收金額,76本行代付筆數,77本行代付金額,78他行代付筆數,79他行代付金額80--------------------代收成功筆數與代收成功金額-------------------81FROM (SELECT MasterKey=ISNULL(a.MasterKey,b.MasterKey),82本行代收筆數,83本行代收金額,84他行代收筆數,85他行代收金額86FROM (SELECT MasterKey,87COUNT(PriKey)AS 本行代收筆數,88SUM(AMT)AS 本行代收金額89FROM ZT_DetailWHERE TXTYPE='SD'AND MasterKeyIN (SELECT PriKeyFROM ZT_MasterWHERE TDATETIMEBETWEEN @.DTBEGAND @.DTEND)ANDSUBSTRING(RBANK, 1, 3) ='822'GROUP BY MasterKey) a90FULLJOIN (SELECT MasterKey,91COUNT(PriKey)AS 他行代收筆數,92SUM(AMT)AS 他行代收金額93FROM ZT_DetailWHERE TXTYPE='SD'AND MasterKeyIN (SELECT PriKeyFROM ZT_MasterWHERE TDATETIMEBETWEEN @.DTBEGAND @.DTEND)ANDSUBSTRING(RBANK, 1, 3) <>'822'GROUP BY MasterKey) b94ON a.MasterKey=b.MasterKey) a95-------------------代付成功筆數與代付成功金額-------------------96FULLJOIN (SELECT MasterKey=ISNULL(a.MasterKey,b.MasterKey),97本行代付筆數,98本行代付金額,99他行代付筆數,100他行代付金額101FROM (SELECT MasterKey,102COUNT(PriKey)AS 本行代付筆數,103SUM(AMT)AS 本行代付金額104FROM ZT_DetailWHERE TXTYPE='SC'AND MasterKeyIN (SELECT PriKeyFROM ZT_MasterWHERE TDATETIMEBETWEEN @.DTBEGAND @.DTEND)ANDSUBSTRING(RBANK, 1, 3) ='822'GROUP BY MasterKey) a105FULLJOIN (SELECT MasterKey,106COUNT(PriKey)AS 他行代付筆數,107SUM(AMT)AS 他行代付金額108FROM ZT_DetailWHERE TXTYPE='SC'AND MasterKeyIN (SELECT PriKeyFROM ZT_MasterWHERE TDATETIMEBETWEEN @.DTBEGAND @.DTEND)ANDSUBSTRING(RBANK, 1, 3) <>'822'GROUP BY MasterKey) b109ON a.MasterKey=b.MasterKey) b110ON a.MasterKey=b.MasterKey) a111--------------------成功筆數與成功金額-----------------------112FULLJOIN (SELECT MasterKey=ISNULL(a.MasterKey,b.MasterKey),113代收成功筆數,114代收成功金額,115代付成功筆數,116代付成功金額117FROM (SELECT MasterKey,118COUNT(PriKey)AS 代收成功筆數,119SUM(AMT)AS 代收成功金額120FROM ZT_DetailWHERE TXTYPE='SD'AND MasterKeyIN (SELECT PriKeyFROM ZT_MasterWHERE TDATETIMEBETWEEN @.DTBEGAND @.DTEND)AND (RCODE='00'OR RCODE='')GROUP BY MasterKey) a121FULLJOIN (SELECT MasterKey,122COUNT(PriKey)AS 代付成功筆數,123SUM(AMT)AS 代付成功金額124FROM ZT_DetailWHERE TXTYPE='SC'AND MasterKeyIN (SELECT PriKeyFROM ZT_MasterWHERE TDATETIMEBETWEEN @.DTBEGAND @.DTEND)AND (RCODE='00'OR RCODE='')GROUP BY MasterKey) b125ON a.MasterKey=b.MasterKey) b126ON a.MasterKey=b.MasterKey) a127---------------------失敗筆數與失敗金額------------------------128FULLJOIN (SELECT MasterKey=ISNULL(a.MasterKey,b.MasterKey),129代收失敗筆數,130代收失敗金額,131代付失敗筆數,132代付失敗金額133FROM (SELECT MasterKey,134COUNT(PriKey)AS 代收失敗筆數,135SUM(AMT)AS 代收失敗金額136FROM ZT_DetailWHERE TXTYPE='SD'AND MasterKeyIN (SELECT PriKeyFROM ZT_MasterWHERE TDATETIMEBETWEEN @.DTBEGAND @.DTEND)AND (RCODE<>'00'AND RCODE<>'')GROUP BY MasterKey) a137FULLJOIN (SELECT MasterKey,138COUNT(PriKey)AS 代付失敗筆數,139SUM(AMT)AS 代付失敗金額140FROM ZT_DetailWHERE TXTYPE='SC'AND MasterKeyIN (SELECT PriKeyFROM ZT_MasterWHERE TDATETIMEBETWEEN @.DTBEGAND @.DTEND)AND (RCODE<>'00'AND RCODE<>'')GROUP BY MasterKey) b141ON a.MasterKey=b.MasterKey) b142ON a.MasterKey=b.MasterKey) b143144145146WHERE a.PriKey=b.MasterKeyAND147--TDateTime BETWEEN @.DTBEG AND @.DTEND AND148TDateTimeBETWEEN'2007/9/5'AND'2007/9/5'AND149150(a.Remark=@.RemarkOR @.Remark=2)AND151(a.BankId=@.BankIdOR @.BankId='')152ORDER BY TDateTime,CustId,PNo153154155156WHERE a.PriKey=b.MasterKeyAND157--TDateTime BETWEEN @.DTBEG AND @.DTEND AND158TDateTimeBETWEEN'2007/9/5'AND'2007/9/5'AND159160(a.Remark=@.RemarkOR @.Remark=2)AND161(a.BankId=@.BankIdOR @.BankId='')162ORDER BY TDateTime,CustId,PNo163164165GO166SET QUOTED_IDENTIFIEROFF167GO168SET ANSI_NULLSON169GO170171

CustID=COALESCE(@.CustID,CustId)

COALESCE function returns the first non-null expression in its expression list.

Refer the below link for more information

http://www.sqlteam.com/article/implementing-a-dynamic-where-clause

Wednesday, March 7, 2012

How to add 'ALL' as report parameter in drop down with other parameters

Hi ALL,
I would like to add 'ALL' to other report parameters.The other report parameters are counties.I would like to add 'all' so that user can select all counties from drop down.

I added union select 'ALL' to sub query.
in main query @.county='all' is it right or wrong.After I did this report is running very very slow.performance problem begins.
what exactly is the procedure to do.
thanks
r sankar

Hi -

You should be able to add an "All Counties" option to your drop down list without a much of a performance hit.

For the dataset that is the basis for the parameter list, have something like this:
SELECT
County,
CountyId
FROM
Counties

UNION

SELECT
'(ALL)', -1
Now in the dataset that the report is based on, include something like this:
SELECT
col1,
col2,
col3,
...,
coln
FROM
tab1
WHERE
(CountyId = @.CountyId OR CountyId = -1)
Of course you'll see performance benefits from wrapping these two statements in stored procedures.

HTH....

--
Joe Webb
SQL Server MVP
http://www.sqlns.com

~~~
Get up to speed quickly with SQLNS
http://www.amazon.com/exec/obidos/tg/detail/-/0972688811

I support PASS, the Professional Association for SQL Server.
(www.sqlpass.org)


|||Joe,
Thank you very much.Explained in very good way.I will try this way.If any problems I will let you know.Thanks once again.
r sankar|||

hi Joe Webbon ,

I've faced this problem , and I'm searching for a better solution for it.


I think this solution is not right . I try it . but it didn't work.
Why?
so it could be :
WHERE (Country.CTRYIsn =98) ====== country no 98
or
WHERE (Country.CTRYIsn = -1) ====== ((((NO DATA))))
because if the report user choose 'ALL' in the drop down menu , the value willl be -1, so, anyone knows that the query results only bring the row which match the value. and because there is not -1 in the country field in the fact table, the results will be 0 ROWS

SELECT BillOfLading.*
FROM Country INNER JOIN
BillOfLading ON Country.CTRYIsn = BillOfLading.CTRYIsn
WHERE (Country.CTRYIsn = - 1)

NO DATA, u see?

-
my idea is :
SELECT
County,
cast (CountyId as varchar(9))
FROM
Counties
UNION
SELECT
'(ALL)', '%'
SELECT BillOfLading.*
FROM Country INNER JOIN
BillOfLading ON Country.CTRYIsn = BillOfLading.CTRYIsn
WHERE (Country.CTRYIsn LIKE @.CTRYIsn)

so it could be :
WHERE (Country.CTRYIsn LIKE 98) ====== country no 98
or
WHERE (Country.CTRYIsn LIKE %) ====== ALL
anyone can find another solution that can high the performance than my sol. , please say it !!!!!!

|||

Rather than comparing the data field to -1 it should have compared the parameter. ie

WHERE (Country.CTRYIsn LIKE @.CTRYIsn OR @.CTRYIsn = -1)

I think this would be be a better solution rather than passing a %.

Cheers

|||Hi,
I use dynamic SQL in the stored procedure to manage the performance issues. I have got multiple drop down with the "All" option. example:

if @.CTRYIsn != '%' begin

set @.vWhere = @.vWhere + ' and s.CTRYIsn = ' + char(39) + @.CTRYIsn + char(39)

end

If you use the new "Multi-Value" property, change this to handle cases where user selected multiple items. I yet have to work on that. I guess that the parameter list will have to be compared to the distinct count of counties to see if the count is 1 or = to the count of counties or in between. if = to 1, then use = if in between then use in(@.CTRYsn) else do not set any limit on the item. What I do not know yet is how to count the items in the parameter list. May be you could count the "," from the parameter list?

Regards,
Philippe

|||

thank u again,

I still can't understand , I think agian your statment are WRONG !!!!
did u try it , or u just propose a solution

dont say an example , My solution before is NOW on use.

Karim

|||Hi Karim -
You're absolutely right. The code I posted will not work as is. There was a typo in it. The code should read:
SELECT
col1,
col2,
col3,
...,
coln
FROM
tab1
WHERE
(CountyId = @.CountyId OR @.CountyId = -1)
The typo was in the second part of the OR clause. It should have the parameter (@.CountyId) as shown above rather than the fieldname (CountyId) as shown in the original post.
When a user selects a specific CountyId in the dropdown, the first part of the OR condition will be satisified. When the user selects the ALL item in the dropdown, the second part of the OR condition will be satisfied for every row in the table.
The solution you posted will certainly return the appropriate resultset, but it will also incurr the performance hit associated with using LIKE. It's not nearly as efficient as comparing two integers.
HTH....and thanks for pointing out the typo!
--
Joe Webb
SQL Server MVP
http://www.sqlns.com

~~~
Get up to speed quickly with SQLNS
http://www.amazon.com/exec/obidos/tg/detail/-/0972688811
I support PASS, the Professional Association for SQL Server.
(www.sqlpass.org)

||| (CountyId = @.CountyId OR @.CountyId = -1)
Actually, you may get better performance if you reverse the order, like this:
(@.CountyId = -1 OR CountyId = @.CountyId)
to take advantage of short-circuit evaluation of the OR operator. Because the expression "@.CountyId = -1" can be evaluated both ahead of time and just once, it may be faster.
For example, in SQL Server 2000, this:
declare @.value varchar(10)
set @.value='All'

select distinct patid from tx_history_all
where
@.value = 'All' or
cost_center_code = @.value
-- or @.value = 'All' is three times faster than this:

declare @.value varchar(10)
set @.value='All'
select distinct patid from tx_history_all
where
-- @.value = 'All' or
cost_center_code = @.value
or @.value = 'All'

|||Hey There --

I think you've gotten your "2000" answer already, so the following is just an FYI...You get multi-parameter select ("All", among other combinations) in 2005, making all the workarounds unnecessary.|||

Very interesting thread...Sounds like 2005 has this issue resolved!

But just for fun I would like to continue the "2000" workarounds...

You see, I was trying to get "(ALL)" or single item capabilities added to existing item range parameters. The user could indicate one item, all items, or a range of items. Here is what I came up with (it's kind of hokey looking but it works):

="select PONUMBER,ITEMNMBR,ITEMDESC,LOCNCODE,VENDORID,UOFM,QTYORDER,REQDATE from POP10110 (NOLOCK) WHERE QTYORDER > 0 " & IIf(Parameters!ItemStart.Value = "(ALL)","AND ITEMNMBR NOT LIKE "," AND ITEMNMBR BETWEEN '" & trim(Parameters!ItemStart.Value) & "' AND ") &
IIf(Parameters!ItemEnd.Value = "(ALL)","'" & trim(Parameters!ItemStart.Value) & "'","'" & trim(Parameters!ItemEnd.Value) & "'")

How to add 'ALL' as report parameter in drop down with other parameters

Hi ALL,
I would like to add 'ALL' to other report parameters.The other report parameters are counties.I would like to add 'all' so that user can select all counties from drop down.

I added union select 'ALL' to sub query.
in main query @.county='all' is it right or wrong.After I did this report is running very very slow.performance problem begins.
what exactly is the procedure to do.
thanks
r sankar

Hi -

You should be able to add an "All Counties" option to your drop down list without a much of a performance hit.

For the dataset that is the basis for the parameter list, have something like this:
SELECT
County,
CountyId
FROM
Counties

UNION

SELECT
'(ALL)', -1
Now in the dataset that the report is based on, include something like this:
SELECT
col1,
col2,
col3,
...,
coln
FROM
tab1
WHERE
(CountyId = @.CountyId OR CountyId = -1)
Of course you'll see performance benefits from wrapping these two statements in stored procedures.

HTH....

--
Joe Webb
SQL Server MVP
http://www.sqlns.com

~~~
Get up to speed quickly with SQLNS
http://www.amazon.com/exec/obidos/tg/detail/-/0972688811

I support PASS, the Professional Association for SQL Server.
(www.sqlpass.org)


|||Joe,
Thank you very much.Explained in very good way.I will try this way.If any problems I will let you know.Thanks once again.
r sankar|||

hi Joe Webbon ,

I've faced this problem , and I'm searching for a better solution for it.


I think this solution is not right . I try it . but it didn't work.
Why?
so it could be :
WHERE (Country.CTRYIsn =98) ====== country no 98
or
WHERE (Country.CTRYIsn = -1) ====== ((((NO DATA))))
because if the report user choose 'ALL' in the drop down menu , the value willl be -1, so, anyone knows that the query results only bring the row which match the value. and because there is not -1 in the country field in the fact table, the results will be 0 ROWS

SELECT BillOfLading.*
FROM Country INNER JOIN
BillOfLading ON Country.CTRYIsn = BillOfLading.CTRYIsn
WHERE (Country.CTRYIsn = - 1)

NO DATA, u see?

-
my idea is :
SELECT
County,
cast (CountyId as varchar(9))
FROM
Counties
UNION
SELECT
'(ALL)', '%'
SELECT BillOfLading.*
FROM Country INNER JOIN
BillOfLading ON Country.CTRYIsn = BillOfLading.CTRYIsn
WHERE (Country.CTRYIsn LIKE @.CTRYIsn)

so it could be :
WHERE (Country.CTRYIsn LIKE 98) ====== country no 98
or
WHERE (Country.CTRYIsn LIKE %) ====== ALL
anyone can find another solution that can high the performance than my sol. , please say it !!!!!!

|||

Rather than comparing the data field to -1 it should have compared the parameter. ie

WHERE (Country.CTRYIsn LIKE @.CTRYIsn OR @.CTRYIsn = -1)

I think this would be be a better solution rather than passing a %.

Cheers

|||Hi,
I use dynamic SQL in the stored procedure to manage the performance issues. I have got multiple drop down with the "All" option. example:

if @.CTRYIsn != '%' begin

set @.vWhere = @.vWhere + ' and s.CTRYIsn = ' + char(39) + @.CTRYIsn + char(39)

end

If you use the new "Multi-Value" property, change this to handle cases where user selected multiple items. I yet have to work on that. I guess that the parameter list will have to be compared to the distinct count of counties to see if the count is 1 or = to the count of counties or in between. if = to 1, then use = if in between then use in(@.CTRYsn) else do not set any limit on the item. What I do not know yet is how to count the items in the parameter list. May be you could count the "," from the parameter list?

Regards,
Philippe

|||

thank u again,

I still can't understand , I think agian your statment are WRONG !!!!
did u try it , or u just propose a solution

dont say an example , My solution before is NOW on use.

Karim

|||Hi Karim -
You're absolutely right. The code I posted will not work as is. There was a typo in it. The code should read:
SELECT
col1,
col2,
col3,
...,
coln
FROM
tab1
WHERE
(CountyId = @.CountyId OR @.CountyId = -1)
The typo was in the second part of the OR clause. It should have the parameter (@.CountyId) as shown above rather than the fieldname (CountyId) as shown in the original post.
When a user selects a specific CountyId in the dropdown, the first part of the OR condition will be satisified. When the user selects the ALL item in the dropdown, the second part of the OR condition will be satisfied for every row in the table.
The solution you posted will certainly return the appropriate resultset, but it will also incurr the performance hit associated with using LIKE. It's not nearly as efficient as comparing two integers.
HTH....and thanks for pointing out the typo!
--
Joe Webb
SQL Server MVP
http://www.sqlns.com

~~~
Get up to speed quickly with SQLNS
http://www.amazon.com/exec/obidos/tg/detail/-/0972688811
I support PASS, the Professional Association for SQL Server.
(www.sqlpass.org)||| (CountyId = @.CountyId OR @.CountyId = -1)
Actually, you may get better performance if you reverse the order, like this:
(@.CountyId = -1 OR CountyId = @.CountyId)
to take advantage of short-circuit evaluation of the OR operator. Because the expression "@.CountyId = -1" can be evaluated both ahead of time and just once, it may be faster.
For example, in SQL Server 2000, this:
declare @.value varchar(10)
set @.value='All'

select distinct patid from tx_history_all
where
@.value = 'All' or
cost_center_code = @.value
-- or @.value = 'All' is three times faster than this:

declare @.value varchar(10)
set @.value='All'
select distinct patid from tx_history_all
where
-- @.value = 'All' or
cost_center_code = @.value
or @.value = 'All'

|||Hey There --

I think you've gotten your "2000" answer already, so the following is just an FYI...You get multi-parameter select ("All", among other combinations) in 2005, making all the workarounds unnecessary.|||

Very interesting thread...Sounds like 2005 has this issue resolved!

But just for fun I would like to continue the "2000" workarounds...

You see, I was trying to get "(ALL)" or single item capabilities added to existing item range parameters. The user could indicate one item, all items, or a range of items. Here is what I came up with (it's kind of hokey looking but it works):

="select PONUMBER,ITEMNMBR,ITEMDESC,LOCNCODE,VENDORID,UOFM,QTYORDER,REQDATE from POP10110 (NOLOCK) WHERE QTYORDER > 0 " & IIf(Parameters!ItemStart.Value = "(ALL)","AND ITEMNMBR NOT LIKE "," AND ITEMNMBR BETWEEN '" & trim(Parameters!ItemStart.Value) & "' AND ") &
IIf(Parameters!ItemEnd.Value = "(ALL)","'" & trim(Parameters!ItemStart.Value) & "'","'" & trim(Parameters!ItemEnd.Value) & "'")

How to add ALL as report parameter in drop down

Hi ALL,
I would like to add 'ALL' to other report parameters.The other report parameters are counties.I would like to add 'all' so that user can select all counties from drop down.

I added union select 'ALL' to sub query.
in main query @.county='all' is it right or wrong.After I did this report is running very very slow.performance problem begins.
what exactly is the procedure to do.
thanks
r sankar

How are you using the counties? I do the same thing, but my countiesalso have a numerical county code. So I union the parameter to have thename as the label and an integer as the value. The query lookssomething like
Select 'All Counties' as nm_county, 0 as id_county
UNION
Select nm_county, id_county from dbo.county
The report still renders just as quickly, and I just check "If@.County = 0" in the stored procedure I use. Hope this helps.
|||Hi,
thank you very much for reply.I did not use @.county =0 in stored procedure .that is why it became slow.Now It is working fine.Thank you once again.If I get any more problems I will let you know.
thanks
sankar|||

You can also reference it directly in a query::

SELECT *
FROM Businesses
WHERE (county = @.county) or (@.county = 'ALL')

This way, you either get Businesses for a specific county or you get all businesses.

How to add a newline sequence

I have a SQL 2005 stored procedure to generate an email when passed parameters such as receipient, subject etc

One of the paramteres passed to it is @.body which is the body text of the message. I want to be able to add a couple of blank lines and then some footer information. This is working right now except I can't find the right way to add newlines into the string within the store procedure, so my footer information just tags right on after the bodytext.

I have tried \n but that literally adds the two characters \ and n

Can anyone advise how to generate newlien sequences in T-SQL.

Regards

Clive

Use the CHAR function e.g. CHAR(13) + CHAR(10)

Seehttp://doc.ddart.net/mssql/sql70/ca-co_4.htm