Showing posts with label value. Show all posts
Showing posts with label value. Show all posts

Wednesday, March 28, 2012

Reporting Services SP using Dynamic Queries

Hey i am using Stored Procedures in Sql Reporting Services.
This SP has some parameters and based on these parameter's value Final query is being created at run time. But when i use this SP in VS.Net Reporting Services as dataset then it doesnt show its fields.

Here I am writing some part of my SP to show how things are working at my end. @.Country , @.StartDate , @.EndDate are SP parameters and based on these parameter’s value, some part of query is being added to main query. So in this case again I am not able to get fields in report.

IF LTRIM(RTRIM(@.Country)) IS NOT NULL

BEGIN
SET @.CountryQuery = " AND ID3.id_value LIKE '" + LTRIM(RTRIM(@.Country)) +"' "
END

IF LTRIM(RTRIM(@.StartDate)) IS NOT NULL AND LTRIM(RTRIM(@.EndDate)) IS NOT NULL
BEGIN
SET @.DateQuery = " AND ( "+@.FieldName+" >= '" + LTRIM(RTRIM(@.StartDate)) + "' AND "+@.FieldName+" <= '" + LTRIM(RTRIM(@.EndDate)) + "' ) "
END

SET @.Query = " SELECT DISTINCT field1, field2, field3 FROM Table1 T1 INNER JOIN Table2 T2 ON T1.id_fk = T2.id_code " + @.CityQuery + " WHERE tr_status =1" + @.DateQuery

EXEC (@.Query)

Even I have used temp table in SP and stored values in it but could not able to get desired result (get fields in report).

PLease help me
Thanks

Hi,

Try these steps:

1. In your DataSet put the query with fixed values (i.e. without parameters):

SELECT DISTINCT field1, field2, field3 FROM Table1 ...

2. Execute the Query

3. Go to the "DataSets Window" and select "refresh"

4. Now you should replace the query above with the Stored Procedure command

I think this solves your problem.

--

Telmo Moreira

Friday, March 23, 2012

Reporting services parameter([rsFieldReference] The Value expression for the...)

@.StartDate is a report parameter and CustomerNo is the field I want to render on the report,I want to combine the sql ,but it display the error message below when I preview the report.If I query in the design form and input the value of the parameter ,it run correctly .

Data sql:

declare @.sql nvarchar(4000)
declare @.sqlWhere nvarchar(4000)

set @.sql='select CustomerNo from table1 '
set @.sqlWhere=''

if @.StartDate<>''
begin
set @.sqlWhere =@.sqlWhere + ' StartDate=''' +@.StartDate + ''''
end

if ltrim(rtrim(@.sqlWhere))<>''
begin
set @.sqlWhere =' where ' + @.sqlWhere
end
set @.sql=@.sql+@.sqlWhere

exec sp_executeSQL @.sql

Error message:

[rsFieldReference] The Value expression for the textbox ‘CustomerNo’ refers to the field ‘CustomerNo’. Report item expressions can only refer to fields within the current data set scope or, if inside an aggregate, the specified data set scope.

I'm a beginner .Help me.

|||

Please give me a answer.

|||

I wrote a procedure and the problem is resolved.

Wednesday, March 21, 2012

Reporting Services non-existant feature-Column Difference Calculation

Hello Guys,

I have struggled to do this in Reporting Services but it does not do what I want it to do...SO

I need to take a value from a column in SQL 2005 table and subtract from a previous column...

For Example:

ID Detail info Year Difference

1 200 2007 50

2 150 2006 10

3 140 2005 0

Please help me to know how to do this in T-SQL...Thank You...

try this:

Code Snippet

declare @.t table(ID int, [Detail info] int, [Year] int)

insertinto @.t values(1, 200, 2007)

insertinto @.t values(2, 150, 2007)

insertinto @.t values(3, 140, 2007)

select ID, [Detail info], [Year],

isnull((select t1.[Detail info] - t2.[Detail info] from @.t t2

where t2.ID = t1.ID + 1),0)as [Difference]

from @.t t1

orderby ID

OR

select t1.ID, t1.[Detail info], t1.[Year],

isnull(t1.[Detail info] - t2.[Detail info], 0)as [Difference]

from @.t t1

leftouterjoin @.t t2

on t1.ID + 1 = t2.ID

orderby ID

|||

Excellent!

Thank You for prompt answer...Now do you know how to take multi-value parameter array values and pass to Sql Stored Proc?

|||

This takes a string of csv and turns it into a "table"

(note...you may want to change the schema...I have int a Utility schema)

Code Snippet

IFEXISTS(

SELECT*FROMsys.objects

WHEREobject_id=OBJECT_ID(N'[Util].[list2set]')

ANDtypein(N'FN', N'IF', N'TF', N'FS', N'FT')

)

DROPFUNCTION [Util].[list2set];

GO

CREATEFUNCTION Util.list2set( @.list nvarchar(max), @.delim nvarchar(10))

RETURNS @.resultset TABLE( pos intidentity, item nvarchar(max))

AS

BEGIN

IFlen(@.list)<1 RETURN;

DECLARE @.xList XML;

-- no validity tests are performed, depending input this could fail

SET @.xList =Convert(XML,'<list><item>'+REPLACE(@.list, @.delim,'</item><item>')+'</item></list>')

INSERTINTO @.resultset

SELECT data.listitem.value('.','nvarchar(max)')as item

FROM @.xList.nodes('/list/item') data(listitem)

RETURN

END

GO

You use it as such:

Select t1.*

FROM MyTable t1

inner join Util.list2set(N'1,2,3,4,5', N',') sel

on t1.ID = sel.Item

The input list can obviously be a variable, and the separator can be anything you want.

You can also modify it to use an XML input.

|||

could you be ever so kind and explain the function line by line and also why the XML stuff...

Thanks...I need a little help getting up to speed since I have been struggling with this issue and feel that I am on the cusp of getting the picture...just need a little push...

Thank You...