Showing posts with label purposes. Show all posts
Showing posts with label purposes. Show all posts

Tuesday, March 20, 2012

Calling CLR stored procedure from within a CLR table-valued function giving errors

We are trying to create a TVF that executes a CLR Stored Procedure we wrote to use the results from the SP and transform them for the purposes of returning to the user as a table.

Code Snippet

[SqlFunction ( FillRowMethodName = "FillRow",

TableDefinition = "CustomerID nvarchar(MAX)",

SystemDataAccess = SystemDataAccessKind.Read,

DataAccess = DataAccessKind.Read,

IsDeterministic=false)]

public static IEnumerable GetWishlist () {

using (SqlConnection conn = new SqlConnection ( "Context Connection=true" )) {

List<string> myList = new List<string> ();

conn.Open ();

SqlCommand command = conn.CreateCommand ();

command.CommandText = "GetObject";

command.Parameters.AddWithValue ( "@.map", "Item" );

command.CommandType = System.Data.CommandType.StoredProcedure;

using ( SqlDataReader reader = command.ExecuteReader ( System.Data.CommandBehavior.SingleRow )) {

if (reader.Read ()) {

myList.Add ( reader[0] as string );

}

}

return (IEnumerable)myList;

}

}

When command.ExecuteReader is called, I am getting an "Object not defined" error. However, the stored procedure can be used in SQL Management Studio just fine.

Code Snippet

EXEC GetObject 'Item'

Is there some sorf of trick I am missing?

Thank you!

Did a little more debugging on our other Stored Procedure within this current scenario and it looks like SqlContext.Pipe is NULL. Now why would the SqlContext.Pipe be null? Anyone?|||You cannot use SqlPipe inside TVF, as well as call stored procedures. This restriction is based on requirement that functions must not change the content of the database, so if functions would be able to call SPs they would be able to update database through these SPs.

Tuesday, February 14, 2012

calculating pecent

Hi,
Iâ'm trying to find a way to calculate percentage of number of customer for
reporting purposes. (Using reporting services)
In analysis manger I have one dimension called area and one measure called
numberOfCustomer. I want to find how many percent of the customers applies to
each area if the total number of customers is 100%.
Example in a report:
---
USA # of customer
North 5 20 %
South 6 24 %
Europe
Germany 10 40 %
UK 4 16 %
Totally 25 100 %
Same calculation (number of customers and percent) should be done for other
dimensions as well in other reports.
How do I calculate a general percent for number of customer? Is it better to
calculate this via a â'Calculated memberâ' in the cube or should I solve it in
reports?
Any hints? Thanks NilofarWe are just starting with RS. The solution we came up with was to use a
"Calculated Field"
We also came to the conclusion that this may be better handled in the cube
in the future.
"Nilofar" wrote:
> Hi,
> Iâ'm trying to find a way to calculate percentage of number of customer for
> reporting purposes. (Using reporting services)
> In analysis manger I have one dimension called area and one measure called
> numberOfCustomer. I want to find how many percent of the customers applies to
> each area if the total number of customers is 100%.
> Example in a report:
> ---
> USA # of customer
> North 5 20 %
> South 6 24 %
> Europe
> Germany 10 40 %
> UK 4 16 %
> Totally 25 100 %
> Same calculation (number of customers and percent) should be done for other
> dimensions as well in other reports.
> How do I calculate a general percent for number of customer? Is it better to
> calculate this via a â'Calculated memberâ' in the cube or should I solve it in
> reports?
> Any hints? Thanks Nilofar