Showing posts with label url. Show all posts
Showing posts with label url. Show all posts

Monday, February 20, 2012

Passing SELECT ALL from URL

Is there a way to pass the "select all" option to a multi-select parameter from a URL string?

Thanks, Eva

Hi,

In the case of multi-select with Select All let's assume 2 cases, a text param and an INT param.

Assuming no default values are set

INT param.

Set the report parameter like that

Param Value, Label = Select All, Value = 2147483647

Set the procedure like that, parameter declaration

@.Value as int = 2147483647

Set the procedure Limit like that

AND ( @.Value = 2147483647 or i.Value <= @.Value)

Then call the URL Like that

http://myname.mydomain.com/ReportServer/Pages/ReportViewer.aspx?%2fNew+Product+Market+Synergy+Reports%2fNP+Market+Synergy&rs%3aCommand=Render&Division=%23%23&project=1763570219&Value=2147483647&OptyDetailsTop=10&rs:format=EXCEL

For Strings use something like

Param Division, Label = All, Value = '##'

or use a dataset for your param like that

Select '##' as Value, '*All' As label
union all
Select distinct
Division as Value, Division_Description as Label from tb_Division
order by Label

in the proc use this param declaration

@.Division as Varchar(85) = '##'

And the limit like that

where ( @.Division = '##' or i2.Division = @.Division)

Then call it like that from the URL

http://myname.mydomain.com/ReportServer/Pages/ReportViewer.aspx?%2fNew+Product+Market+Synergy+Reports%2fNP+Market+Synergy&rs%3aCommand=Render&Division=%23%23&project=1763570219&Value=2147483647&OptyDetailsTop=10&rs:format=PDF

Where %23%23 will pass the ## to the procedure parameter.

Note that if you simply want to display the report, remove the &rs:format tag from the URL.

Since the procedure limit start with @.Division = '##' the i2.Division = @.Division will not even be part of the query sent to the server.

Regards,

Philippe

|||If I do something like you suggest RS puts the Select ALL option at the top of the multi-select parameter. Selecting both the RS select all option and the one I built in makes the queries not work. Therefore, I really just want to leave the datasets clean and the parameters in my main query TableField in (@.param) and just be able to send the URL something that tells it I want that default RS Select ALL option as if I had set that thing as the default value of the parameter.|||

Oops sorry, the example where I craft the select all was for a single select or a pre-SP2 install.

For a multi-select with built-in Select all you would actually just use the standard list of values. here the trick to avoid a huge Where Item is IN ('a', 'b', 'c',......) would be to do it like this

Procedure parameter

, @.Item varchar(Max) = '##'

Procedure handling of ALL option.

declare @.NKeyCount as int

declare @.NKeyMax as int

set @.NKeyCount = onglobals.dbo.fn_CountChar(@.Item, ',')

set @.NKeyMax = (

Select Count(Distinct b.Item_Cd) as Value

from meta_NewProductBaseline b

)

if @.NKeyCount + 1 = @.NKeyMax begin set @.Item = '##' end

If @.Item is null begin set @.Item = '##' end

Procedure limit

And (@.Item = '##' or b.Item_Cd in (select ltrim(SQLstr) from ONGlobals.dbo.clrfn_SplitCommaDelimitedString(@.Item) ) )

Unfortunately, you need a bunch of functions to get it to work. I hope you already have those functions. If not, you can try to find it from this forum or I can give you the code.

Philippe

|||

OK, Here is the code for the 2 functions. one is SQL the other is CLR.

You do not have to use CLR, there are multiple other ways to do this.

See

http://www.sqlservercentral.com/forums/shwmessage.aspx?forumid=399&messageid=386759

Also, note that the CLR I show here is limited to 4000 chars and miss a build-in LTRIM...

Count chars

Code Snippet

CREATE FUNCTION dbo.fn_countchar (@.source varchar(max), @.charval varchar(255))

returns int

as

BEGIN

DECLARE @.len int, @.icount int, @.count int

SET @.len = len(@.source)

SET @.icount = 1

SET @.count = 0

WHILE @.icount<= @.len

BEGIN

IF substring(@.source, @.icount, 1) = @.charval

SET @.count = @.count + 1

SET @.icount = @.icount +1

END

RETURN @.count

end

Split multi-param

Code Snippet

using System;

using System.Data;

using System.Data.SqlClient;

using System.Data.SqlTypes;

using Microsoft.SqlServer.Server;

public partial class UserDefinedFunctions

{

[Microsoft.SqlServer.Server.SqlFunction(IsDeterministic = true, IsPrecise = true, TableDefinition = "SQLStr nvarchar(4000)", FillRowMethodName = "FillSplitCommaDelimitedStringToStr")]

public static System.Collections.IEnumerable clrfn_SplitCommaDelimitedString(SqlString str)

{

string x = str.Value;

if (!string.IsNullOrEmpty(x))

{

return x.Split(',');

}

else

{

return null;

}

}

private static void FillSplitCommaDelimitedStringToStr(object obj, out SqlString str)

{

if (obj != null)

str = (String)(obj);

else

str = String.Empty;

}

};

|||

How do I pass this any values from a URL string?

|||

SAme as previously posted. You call the report via URL and the report will call the procedure.

http://myname.mydomain.com/ReportServer/Pages/ReportViewer.aspx?%2fNew+Product+Market+Synergy+Reports%2fNP+Market+Synergy&rs%3aCommand=Render&Division=%23%23&project=1763570219&Value=2147483647&OptyDetailsTop=10&rs:format=EXCEL

Use %23%23 to pass ## meaning ALL otherwhise pass the standard list of values for a multiselect or just select all in the multiselect.

Philippe

Passing SELECT ALL from URL

Is there a way to pass the "select all" option to a multi-select parameter from a URL string?

Thanks, Eva

Hi,

In the case of multi-select with Select All let's assume 2 cases, a text param and an INT param.

Assuming no default values are set

INT param.

Set the report parameter like that

Param Value, Label = Select All, Value = 2147483647

Set the procedure like that, parameter declaration

@.Value as int = 2147483647

Set the procedure Limit like that

AND ( @.Value = 2147483647 or i.Value <= @.Value)

Then call the URL Like that

http://myname.mydomain.com/ReportServer/Pages/ReportViewer.aspx?%2fNew+Product+Market+Synergy+Reports%2fNP+Market+Synergy&rs%3aCommand=Render&Division=%23%23&project=1763570219&Value=2147483647&OptyDetailsTop=10&rs:format=EXCEL

For Strings use something like

Param Division, Label = All, Value = '##'

or use a dataset for your param like that

Select '##' as Value, '*All' As label
union all
Select distinct
Division as Value, Division_Description as Label from tb_Division
order by Label

in the proc use this param declaration

@.Division as Varchar(85) = '##'

And the limit like that

where ( @.Division = '##' or i2.Division = @.Division)

Then call it like that from the URL

http://myname.mydomain.com/ReportServer/Pages/ReportViewer.aspx?%2fNew+Product+Market+Synergy+Reports%2fNP+Market+Synergy&rs%3aCommand=Render&Division=%23%23&project=1763570219&Value=2147483647&OptyDetailsTop=10&rs:format=PDF

Where %23%23 will pass the ## to the procedure parameter.

Note that if you simply want to display the report, remove the &rs:format tag from the URL.

Since the procedure limit start with @.Division = '##' the i2.Division = @.Division will not even be part of the query sent to the server.

Regards,

Philippe

|||If I do something like you suggest RS puts the Select ALL option at the top of the multi-select parameter. Selecting both the RS select all option and the one I built in makes the queries not work. Therefore, I really just want to leave the datasets clean and the parameters in my main query TableField in (@.param) and just be able to send the URL something that tells it I want that default RS Select ALL option as if I had set that thing as the default value of the parameter.|||

Oops sorry, the example where I craft the select all was for a single select or a pre-SP2 install.

For a multi-select with built-in Select all you would actually just use the standard list of values. here the trick to avoid a huge Where Item is IN ('a', 'b', 'c',......) would be to do it like this

Procedure parameter

, @.Item varchar(Max) = '##'

Procedure handling of ALL option.

declare @.NKeyCount as int

declare @.NKeyMax as int

set @.NKeyCount = onglobals.dbo.fn_CountChar(@.Item, ',')

set @.NKeyMax = (

Select Count(Distinct b.Item_Cd) as Value

from meta_NewProductBaseline b

)

if @.NKeyCount + 1 = @.NKeyMax begin set @.Item = '##' end

If @.Item is null begin set @.Item = '##' end

Procedure limit

And (@.Item = '##' or b.Item_Cd in (select ltrim(SQLstr) from ONGlobals.dbo.clrfn_SplitCommaDelimitedString(@.Item) ) )

Unfortunately, you need a bunch of functions to get it to work. I hope you already have those functions. If not, you can try to find it from this forum or I can give you the code.

Philippe

|||

OK, Here is the code for the 2 functions. one is SQL the other is CLR.

You do not have to use CLR, there are multiple other ways to do this.

See

http://www.sqlservercentral.com/forums/shwmessage.aspx?forumid=399&messageid=386759

Also, note that the CLR I show here is limited to 4000 chars and miss a build-in LTRIM...

Count chars

Code Snippet

CREATE FUNCTION dbo.fn_countchar (@.source varchar(max), @.charval varchar(255))

returns int

as

BEGIN

DECLARE @.len int, @.icount int, @.count int

SET @.len = len(@.source)

SET @.icount = 1

SET @.count = 0

WHILE @.icount<= @.len

BEGIN

IF substring(@.source, @.icount, 1) = @.charval

SET @.count = @.count + 1

SET @.icount = @.icount +1

END

RETURN @.count

end

Split multi-param

Code Snippet

using System;

using System.Data;

using System.Data.SqlClient;

using System.Data.SqlTypes;

using Microsoft.SqlServer.Server;

public partial class UserDefinedFunctions

{

[Microsoft.SqlServer.Server.SqlFunction(IsDeterministic = true, IsPrecise = true, TableDefinition = "SQLStr nvarchar(4000)", FillRowMethodName = "FillSplitCommaDelimitedStringToStr")]

public static System.Collections.IEnumerable clrfn_SplitCommaDelimitedString(SqlString str)

{

string x = str.Value;

if (!string.IsNullOrEmpty(x))

{

return x.Split(',');

}

else

{

return null;

}

}

private static void FillSplitCommaDelimitedStringToStr(object obj, out SqlString str)

{

if (obj != null)

str = (String)(obj);

else

str = String.Empty;

}

};

|||

How do I pass this any values from a URL string?

|||

SAme as previously posted. You call the report via URL and the report will call the procedure.

http://myname.mydomain.com/ReportServer/Pages/ReportViewer.aspx?%2fNew+Product+Market+Synergy+Reports%2fNP+Market+Synergy&rs%3aCommand=Render&Division=%23%23&project=1763570219&Value=2147483647&OptyDetailsTop=10&rs:format=EXCEL

Use %23%23 to pass ## meaning ALL otherwhise pass the standard list of values for a multiselect or just select all in the multiselect.

Philippe

Passing Report Parameters through URL

Hi, I've read some threads in regards to passing report parameters through the 'URL' but I am struggling to fully understand. To keep things simple I have 1 report parameter, named par_pub which brings back either ww06 or ww07. What I require is to click on a hyperlink and it directs me to my report and then populates the par_pub paramerter with ww07.

I am trying the below

http://emp6/Reports/Pages/Report.aspx?ItemPath=%2fTest+Reports%2fIT+Dev%2fSales+Summary+Detail&prefixStick out tonguear_pub=%WW07%

The part in bold is the location + name of the report and the later is where I am trying to pass the parameter. Can anyone please help as this is not working.

Thanks

Quarry,

I tried using parameter in reportserver (instead of manager) and they worked fine.

reportserver can be launched as http://server_name/reportserver.

No idea why they are not working with report manager.

|||

Quarry,

I've gotten my reports to work with passing parameters through the URL; with the exception of date fields. They have been giving me fits. To answer your question though, try this:

Try opening a browser and start off just typing the name of your report server's URL. For instance: http://machinename/reportServicesInstancename.

That will open up the list of folders where your reports are located. Click on the folders and files until you have selected and opened your report. Then go into the address box and copy that value. Paste that into your code as the string you want to deal with and appendan "&par_pub=WWW07" to it (I'm not sure why you have %'s around the WWW07 there, unless it's something your app needs.

Ron

|||

Hi Ron, I've tried this but my URL link opens up the report in Report Manager but does not poplulate the parameter value.

|||

Irrespective of URL,when you select the parameter manually, like "www07".does the URL get changed? If not there is no point we can pass parameter through URL?

if this is true, the other way we are speaking should be true.

Guys,please correct me if i am not correct.

I dont have Enough knowledge on passing parameters through URL,if you have done any work around before like this.defly i am interested share to knowledge.

Once again,please correct me if i am wrong.I am not sure

|||I have tried this manually as you suggested, and the URL does not change when I select a parameter value. Does this mean that I cannot pass the value of the parameter from within my URL link to my report in Report Manger?|||

It's not going to change when you select it manually. The reason I was telling you to open it up manually is to make sure that you have the first part of the string working correctly. Once you have the report opened, select the entire path and all querystring parameters that are included along with it there in the address bar. I would then suggest you open up a new browser window and try pasting that into the browser window and make sure that when you select it, it will run (without the parameter being set yet). If it does work, then go into the address bar in the very same window and add in the "&parametername=parameterValue" statement and try running it again from the command line.

In other words, get your report running (using your parameter) from the command line first. Once you do that, THEN go paste that line of code into your code and get it running via code. I just find this approach more easier than trying to debug from within code when I have SSRS syntax errors.

|||

How did you solve the problem?

I have the same issue?

Thanks

Passing Report Parameters through URL

Hi, I've read some threads in regards to passing report parameters through the 'URL' but I am struggling to fully understand. To keep things simple I have 1 report parameter, named par_pub which brings back either ww06 or ww07. What I require is to click on a hyperlink and it directs me to my report and then populates the par_pub paramerter with ww07.

I am trying the below

http://emp6/Reports/Pages/Report.aspx?ItemPath=%2fTest+Reports%2fIT+Dev%2fSales+Summary+Detail&prefixStick out tonguear_pub=%WW07%

The part in bold is the location + name of the report and the later is where I am trying to pass the parameter. Can anyone please help as this is not working.

Thanks

Quarry,

I tried using parameter in reportserver (instead of manager) and they worked fine.

reportserver can be launched as http://server_name/reportserver.

No idea why they are not working with report manager.

|||

Quarry,

I've gotten my reports to work with passing parameters through the URL; with the exception of date fields. They have been giving me fits. To answer your question though, try this:

Try opening a browser and start off just typing the name of your report server's URL. For instance: http://machinename/reportServicesInstancename.

That will open up the list of folders where your reports are located. Click on the folders and files until you have selected and opened your report. Then go into the address box and copy that value. Paste that into your code as the string you want to deal with and appendan "&par_pub=WWW07" to it (I'm not sure why you have %'s around the WWW07 there, unless it's something your app needs.

Ron

|||

Hi Ron, I've tried this but my URL link opens up the report in Report Manager but does not poplulate the parameter value.

|||

Irrespective of URL,when you select the parameter manually, like "www07".does the URL get changed? If not there is no point we can pass parameter through URL?

if this is true, the other way we are speaking should be true.

Guys,please correct me if i am not correct.

I dont have Enough knowledge on passing parameters through URL,if you have done any work around before like this.defly i am interested share to knowledge.

Once again,please correct me if i am wrong.I am not sure

|||I have tried this manually as you suggested, and the URL does not change when I select a parameter value. Does this mean that I cannot pass the value of the parameter from within my URL link to my report in Report Manger?|||

It's not going to change when you select it manually. The reason I was telling you to open it up manually is to make sure that you have the first part of the string working correctly. Once you have the report opened, select the entire path and all querystring parameters that are included along with it there in the address bar. I would then suggest you open up a new browser window and try pasting that into the browser window and make sure that when you select it, it will run (without the parameter being set yet). If it does work, then go into the address bar in the very same window and add in the "&parametername=parameterValue" statement and try running it again from the command line.

In other words, get your report running (using your parameter) from the command line first. Once you do that, THEN go paste that line of code into your code and get it running via code. I just find this approach more easier than trying to debug from within code when I have SSRS syntax errors.

|||

How did you solve the problem?

I have the same issue?

Thanks