Showing posts with label according. Show all posts
Showing posts with label according. Show all posts

Monday, March 26, 2012

dynamic query

I need to change the query, according to the parameter I get from url to the reporting services.

For example,

if url =http://localhost:reportserver/parmeter=true?param1=A

then, I need to use a "query1" for the report . If param1 = B, then I need to use "query2".

I would like to know whether this is possible..

thanks,

I suggest using a stored procedure as the dataset for your target report.

The stored procedure would accept as its one parameter the report parameter of the target report and run the required query accordingly.



dynamic queries

Hi,

I have a parameter in the url to the report. According to that parameter, I need to change the query. For example, url = http://localhost/reportserver?param1=A

if Param1=A, then I need to use query1 for the report

if param1 = B, then I need to use query2 for the report.

I would like to know if I can do this. If not, is there any other way to build query dynamically in the report.

thanks

Hi,

you can use a stored procedure for this, using the inside procedural logic for deciding which query should be executed.

HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de
sql

Thursday, March 22, 2012

Dynamic Parameters S.P.

Using a Stored procedure, i want to sort my records according to a dynamic
field... Could be sort by firstName, CompanyName, UserID... and so on...
Receiving value in @.orderingBy, but i can't seem to find a way to properly
integrate it into my query, juse into the 'order by'...
If any could help...
CREATE PROCEDURE [dbo].[SelectContactListTEST]
@.orderingBy nvarchar (255)
AS
SELECT UO.g_user_id AS userid, UO.g_org_id AS orgid
FROM UserObject UO INNER JOIN
WHERE (UO.customer_type = 'wholesaler') AND (UO.Activated IN (0, 1)) AND
(UO.Hidden = 0)
ORDER BY "+ @.orderingBy + "How do I use a variable in an ORDER BY clause?
http://www.aspfaq.com/show.asp?id=2501
AMB
"lp_rochon" wrote:

> Using a Stored procedure, i want to sort my records according to a dynamic
> field... Could be sort by firstName, CompanyName, UserID... and so on...
> Receiving value in @.orderingBy, but i can't seem to find a way to properly
> integrate it into my query, juse into the 'order by'...
> If any could help...
>
> CREATE PROCEDURE [dbo].[SelectContactListTEST]
> @.orderingBy nvarchar (255)
> AS
> SELECT UO.g_user_id AS userid, UO.g_org_id AS orgid
> FROM UserObject UO INNER JOIN
> WHERE (UO.customer_type = 'wholesaler') AND (UO.Activated IN (0, 1)) A
ND
> (UO.Hidden = 0)
> ORDER BY "+ @.orderingBy + "|||Thank alot, it does work..
But now, to next question:
I the same aspect, i got my 'where' statement that i need to be dynamic...
As:
WHERE (UO.customer_type = 'wholesaler')
could become:
WHERE (UO.customer_type = 'wholesaler') AND (UO.A = 'XX') AND (UO.B =
'ZZ')
to do that, i want to pass 1 variable (string) as:
WHERE (UO.customer_type = 'wholesaler') @.whereString
know how to do this?
"Alejandro Mesa" wrote:

> How do I use a variable in an ORDER BY clause?
> http://www.aspfaq.com/show.asp?id=2501
>
> AMB
>|||And now to a new problem...
Calling my procedure, passing this
EXEC SelectContactListTEST '0','1','0','lastname','ASC'
I'm getting the following error:
erver: Msg 245, Level 16, State 1, Procedure SelectContactListTEST, Line 9
[Microsoft][ODBC SQL Server Driver][SQL Server]Syntax error converting the
nvarchar value 'TEST' to a column of data type bit.
I really don't see were this 'TEST' column comes from...
See below for code
----
--
CREATE PROCEDURE [dbo].[SelectContactListTEST]
@.activeSearch bit,
@.activeSearch2 bit,
@.hiddenSearch bit,
@.orderingBy nvarchar (255),
@.orderingWay nvarchar (255)
AS
SELECT UO.g_user_id AS userid, UO.g_org_id AS orgid, UO.company AS
company, UO.ContOwner AS contowner, UO.u_first_name AS firstname,
UO.u_last_name AS lastname, UO.u_email_address AS
email, UO.Hidden AS hidden, UO.Activated AS activated, UO.d_date_created AS
datecreated,
A.u_city AS city, A.u_country_code AS country,
A.u_region_code AS region
FROM UserObject UO INNER JOIN
Addresses A ON UO.g_user_id = A.g_id
WHERE (UO.customer_type = 'wholesaler') AND (UO.Activated IN
(@.activeSearch,@.activeSearch2)) AND (UO.Hidden = @.hiddenSearch)
ORDER BY
case @.orderingWay
when 'desc' then
CASE @.orderingBy
WHEN 'company' then company
WHEN 'lastname' then u_last_name
WHEN 'country' then u_country_code
WHEN 'region' then u_region_code
WHEN 'city' then u_city
WHEN 'email' then u_email_address
WHEN 'activated' then Activated
end
END
DESC,
case @.orderingWay
when 'ASC' then
CASE @.orderingBy
WHEN 'company' then company
WHEN 'lastname' then u_last_name
WHEN 'country' then u_country_code
WHEN 'region' then u_region_code
WHEN 'city' then u_city
WHEN 'email' then u_email_address
WHEN 'activated' then Activated
end
END
GO
---
"Alejandro Mesa" wrote:

> How do I use a variable in an ORDER BY clause?
> http://www.aspfaq.com/show.asp?id=2501
>
> AMB
>|||On Tue, 8 Feb 2005 09:03:01 -0800, lp_rochon wrote:

>And now to a new problem...
>
>Calling my procedure, passing this
>EXEC SelectContactListTEST '0','1','0','lastname','ASC'
>I'm getting the following error:
>erver: Msg 245, Level 16, State 1, Procedure SelectContactListTEST, Line 9
>[Microsoft][ODBC SQL Server Driver][SQL Server]Syntax error converting the
>nvarchar value 'TEST' to a column of data type bit.
>I really don't see were this 'TEST' column comes from...
Hi lp_rochon,
I guess it's in your data, as one of the last names.
Look at this part:

> case @.orderingWay
> when 'ASC' then
> CASE @.orderingBy
> WHEN 'company' then company
> WHEN 'lastname' then u_last_name
> WHEN 'country' then u_country_code
> WHEN 'region' then u_region_code
> WHEN 'city' then u_city
> WHEN 'email' then u_email_address
> WHEN 'activated' then Activated
> end
> END
I assume that all columns here are char, varchar nchar or nvarchar, except
for the Activated column, which I guess to be bit. The datatype of the
CASE is determined by looking at all datatypes used in the WHEN
expressions; if they are different (and no explicit conversion is used),
then datatype precedence decides which is converted to what. In this case,
SQL Server will attempt to convert all varchar columnsto bit, since bit
has a higher precedence than varchar.
Try changing your ORDER BY to either
ORDER BY
case @.orderingWay
when 'desc' then
CASE @.orderingBy
WHEN 'company' then company
WHEN 'lastname' then u_last_name
WHEN 'country' then u_country_code
WHEN 'region' then u_region_code
WHEN 'city' then u_city
WHEN 'email' then u_email_address
WHEN 'activated' then CAST(Activated as char(1))
end
END
DESC,
case @.orderingWay
when 'ASC' then
CASE @.orderingBy
WHEN 'company' then company
WHEN 'lastname' then u_last_name
WHEN 'country' then u_country_code
WHEN 'region' then u_region_code
WHEN 'city' then u_city
WHEN 'email' then u_email_address
WHEN 'activated' then CAST(Activated as char(1))
end
END
or
ORDER BY
case @.orderingWay
when 'desc' then
CASE @.orderingBy
WHEN 'company' then company
WHEN 'lastname' then u_last_name
WHEN 'country' then u_country_code
WHEN 'region' then u_region_code
WHEN 'city' then u_city
WHEN 'email' then u_email_address
end
END
DESC,
case @.orderingWay
when 'desc' then
CASE @.orderingBy
WHEN 'activated' then Activated
end
END
DESC,
case @.orderingWay
when 'ASC' then
CASE @.orderingBy
WHEN 'company' then company
WHEN 'lastname' then u_last_name
WHEN 'country' then u_country_code
WHEN 'region' then u_region_code
WHEN 'city' then u_city
WHEN 'email' then u_email_address
end
END,
case @.orderingWay
when 'ASC' then
CASE @.orderingBy
WHEN 'activated' then Activated
end
END
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)

Monday, March 19, 2012

Dynamic graphs in SSRS

Hello,

Im building a horizontal bar graph, but according to the parameters it could have a different number of bars, how can i make the SSRS resize the graph?

Or how can i make ssrs to give the same size as a table right next to it?

Thank you

You may need to create a couple of separate graphs with different sizes and show-hide based on # of rows in the dataset.

There is an article here which may also help, though it is more for working inside the chart rather than sizing the object itself. http://www.ssw.com.au/ssw/Standards/Rules/RulesToBetterSQLReportingServices.aspx#maxminvalues

A more flexible approach may be available in Dundas Charts for Reporting Services.

More info here:
http://msdn2.microsoft.com/en-us/library/aa964128.aspx

cheers,
Andrew

Sunday, February 19, 2012

dynamic columns in matrix

hi all,

i m using ssrs 2005. i want to generate a report which displays data according to the dataset returned.Now this dataset can return any number of columns.

does matrix use helps out in this case..

if anyone can really explain me on it or can even point to certain articles in this regard,that wudd be wonderful

thanks a ton...

hi all
m quite new to reporting services so may b it sounds easy for u champs but still ur replies wudd b appreciated..

thanks a ton ...

|||Hi,hilander:
Try to do this.
1. Convert your RDL files in RLDC files (see this topic at VS2005 help).
2. Configure your ReportViewer to a LocalReport mode. This will allow you to
link yourdataset to a report at runtime by using ReportViewer.LocalReport methods or at disign level too.

Hopefully I help you.

|||

Hi,hilander:
We are marking this issue as "Answered". If you have any new findings or concerns, please feel free to unmark the issue.
Thank you for your understanding!

Wednesday, February 15, 2012

dynamic aliases/columns

Hi
Is it possible to return a table that its aliases are changing according to
varaiables ?
For example: I would like to use something like (ofcourse it doesn't work).
declare @.p1,@.p2 varchar(30)
set @.p1 ='blhablha'
set @.p2 ='hghfg'
select field1 as @.p1, field2 as @.p2 from table1Only with dynamic SQL (sp_executesql or exec). Most of the time,
however, dynamic SQL is not really a terrific idea. Here is Erland
Sommarskog's page on dynamic SQL (a frequently referenced page):
http://www.sommarskog.se/dynamic_sql.html
I can't imagine why you'd actually want to do this. What are you trying
to achieve?
*mike hodgson*
blog: http://sqlnerd.blogspot.com
romy wrote:

>Hi
>Is it possible to return a table that its aliases are changing according to
>varaiables ?
>For example: I would like to use something like (ofcourse it doesn't work)
.
>
>declare @.p1,@.p2 varchar(30)
>set @.p1 ='blhablha'
>set @.p2 ='hghfg'
>select field1 as @.p1, field2 as @.p2 from table1
>
>|||rommy
if changing alias is only problem
you can use the trick of if condition in sp of CASE in query.Post your
script to suggest you better.
Regards
R.D
"romy" wrote:

> Hi
> Is it possible to return a table that its aliases are changing according t
o
> varaiables ?
> For example: I would like to use something like (ofcourse it doesn't work
).
>
> declare @.p1,@.p2 varchar(30)
> set @.p1 ='blhablha'
> set @.p2 ='hghfg'
> select field1 as @.p1, field2 as @.p2 from table1
>
>|||While I can't think of why you would need to do this on the server,
you could use put the results into a table, rename the columns
with sp_rename (which accepts parameters), then select the contents
of the table.
declare
@.cname1 sysname,
@.cname2 sysname
set @.cname1 = N'lName'
set @.cname2 = N'ID'
select LastName, EmployeeID
into #tmp
from Northwind..Employees
exec tempdb..sp_rename N'#tmp.LastName', @.cname1, 'COLUMN'
exec tempdb..sp_rename N'#tmp.EmployeeID', @.cname2, 'COLUMN'
select * from #tmp
drop table #tmp
Steve Kass
Drew University
romy wrote:

>Hi
>Is it possible to return a table that its aliases are changing according to
>varaiables ?
>For example: I would like to use something like (ofcourse it doesn't work)
.
>
>declare @.p1,@.p2 varchar(30)
>set @.p1 ='blhablha'
>set @.p2 ='hghfg'
>select field1 as @.p1, field2 as @.p2 from table1
>
>