Showing posts with label function. Show all posts
Showing posts with label function. Show all posts

Friday, March 30, 2012

parameter passing problem


why this wont work?

error:
Exception Details: System.Data.SqlClient.SqlException: Procedure or Function 'test1' expects parameter '@.cid', which was not supplied.

.............................................................
ASPX CODE:
string cid12;
cid12 = "user5";
// Connection
ConnectionStringSettings mysettings;
mysettings = System.Configuration.ConfigurationManager.ConnectionStrings["dbase1_connection"];
string myConnectionString = mysettings.ConnectionString;
SqlConnection conn1 = new SqlConnection(myConnectionString);

SqlCommand cmd = new SqlCommand();
cmd.Connection = conn1;
cmd.CommandText = "test1";
cmd.CommandType = CommandType.StoredProcedure;

SqlParameter param = cmd.Parameters.Add("@.cid", SqlDbType.NChar, 20);
param.Direction = ParameterDirection.Input;
param.Value = cid12;

conn1.Open();
cmd.ExecuteNonQuery();
conn1.Close();
.............................................................

STORED PROCEDURE:
ALTER PROCEDURE dbo.test1
(
@.cid nvarchar(20)
)
AS
/* SET NOCOUNT ON */
select tech_id, customer_id, issue_main from [case] where customer_id = @.cid
--GO
RETURN

.............................................................

im using asp.net, C#, and sql express
forgive me. im new to this .net
PLS HELP

pls ignore the post above. i found out that nothing is wrong with that code. i discovered that one on my grid view tables is causing the issue and it is indeed not passing a parameter and thats the reason why i have wasted 12hrs looking at my monitor. hehehe.

my fault. im just human. forgive me.

thanks to you all.

parameter passing problem


why this wont work?
error:
Exception Details: System.Data.SqlClient.SqlException: Procedure or Function 'test1' expects parameter '@.cid', which was not supplied.
.................................................................................
ASPX CODE:
string cid12;
cid12 = "user5";
// Connection
ConnectionStringSettings mysettings;
mysettings = System.Configuration.ConfigurationManager.ConnectionStrings["dbase1_connection"];
string myConnectionString = mysettings.ConnectionString;
SqlConnection conn1 = new SqlConnection(myConnectionString);
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn1;
cmd.CommandText = "test1";
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter param = cmd.Parameters.Add("@.cid", SqlDbType.NChar, 20);
param.Direction = ParameterDirection.Input;
param.Value = cid12;

conn1.Open();
cmd.ExecuteNonQuery();
conn1.Close();
.................................................................................
STORED PROCEDURE:
ALTER PROCEDURE dbo.test1
(
@.cid nvarchar(20)
)
AS
/* SET NOCOUNT ON */
select tech_id, customer_id, issue_main from [case] where customer_id = @.cid
--GO
RETURN
.................................................................................
im using asp.net, C#, and sql express
forgive me. im new to this .net
PLS HELP

forgive me. i found out that the codes above are just ok. i found out that one of my grid table is the one causing the problem - it is not passing a parameter. hehehe. my fault. im just human.

thanks to you all.

Wednesday, March 28, 2012

Parameter name getting garbled

I have a function that calls a sproc, and passes in a bunch of parameters. One of the parameters is named @.ProcessorEmail. Occasionally, the parameter name apparently gets garbled at runtime, as the following error occurs:

System.Data.SqlClient.SqlException: @.ProcessorEm??. is not a parameter for procedure gUser

The "@.ProcessorEm" part is always fine, then there will be various characters in place of the "ail" part.

Any ideas?Does your code hardcode the params or are they been fetched/constructed?|||They are hardcoded. The rest of the params are fine, it is always this same parameter that gets messed up. Again, it does not happen every time, just occasionally.|||Does the data your sending in the param contain any control codes or slighly odd unicode (i.e. taking data from a non .net source)?|||Actually, the parameter in question is being passed as an output parameter, so it does not have a value when I am passing it.|||What data is returned from the proc? Is it only outputs or a combination of outputs and record-sets?|||A combination of outputs. The sproc accepts a single input sproc, then the rest of the params are output params, with only a single record being returned. The param being passed in is an email address, which is the primary key constraint in the table, so there should be no dupes.|||Do you ensure that you've processed *every* row of the record set before you attempt to access the output params?|||Sorry, I misspoke. It is only output parameters, no recordsets.|||Odd one, are you sharing the command object or creating a fresh one each time?|||It's new on each instantiation. The command resides in a class I created called User. There are two constructors for User, one accepts the userid, the other accepts the email address. The only way to run the sproc is to create a new User object in my code.

Dim mUser as New User("me@.domain.com")

Friday, March 23, 2012

ParallelPeriod, Subcubes, and SP2

We're defining some KPIs that include trend expressions which use the ParallelPeriod function to calculate the change in a KPI value since a past time period. For example, we calculate the change in the KPI value

When we use an MDX SELECT with a WHERE clause that specifies a time slice, the expression evaluates correctly.

However, when we use CREATE SUBCUBE to do the filter, or use BI Studio (which creates a subcube), the result is incorrect. In particular, the there's an IsEmpty check for the parallel period of the KPI value, so we're not doing bogus math when there's no data for the previous period. With the WHERE clause, that works fine, but with the subcube, the ParallelPeriod always evaluates to empty.

As a point of comparison, I tested with the Adventure Works cube, usign the "Internet Revenue" KPI, which includes a similar type of KPI trend (revenue for Current Time Member - Revenue for previous Fiscal Year). I see the same behavior there. This:
select
{KPIValue("Internet Revenue"), KPIGoal("Internet Revenue"), KPIStatus("Internet Revenue"), KPITrend("Internet Revenue")}
on columns
from
[Adventure Works]
where {[Date].[Fiscal Year].&[2004]}

returns 1 for the trend, but this:

CREATE SUBCUBE [Adventure Works] AS ( SELECT ( { [Date].[Fiscal Year].&[2004] } ) ON COLUMNS FROM [Adventure Works])

select
{KPIValue("Internet Revenue"), KPIGoal("Internet Revenue"), KPIStatus("Internet Revenue"), KPITrend("Internet Revenue")}
on columns
from
[Adventure Works]

returns 0.

So after lots of reading, I THOUGHT that SP2 fixed this problem. However, we installed the December CTP of SP2, and it doesn't seem to.Since subselects and CREATE SUBCUBE do not set current coordinate on non-aggregatable attributes, functions which look at them (such as ParallelPeriod, PrevMember, Lag, Parent, LastChild etc) won't apply. There were no change in SP2 in this respect. You can still use WHERE clause to set the current coordinate though.|||Ouch. I'm not sure how I came to believe this was being fixed in SP2.

Does Microsoft consider this a bug? Design limitation? Any plans to address it at some point?

Since we have no control over how query tools generate their MDX, it seems difficult to design a cube that uses these functions and have confidence that it will work correctly for our customers.|||

This is not a bug, but rather a design decision. Perhaps it can be reconsidered in the future versions. I don't know which tool you use, but at least Excel 2007 wihch makes extensive use of subselects, does use WHERE clause when the slice is a single member (and ParallelPeriod won't work on multi-select anyways).

HTH,

Mosha.

|||I was quite concerned about Excel 2007, as I saw lots of mentions that Excel uses subselects and subcubes out on the web. However, I did some quick testing, and as you say, it does seem to use the where clause in this case. That makes me feel a little better. Our QA people have mostly been testing with the BI Studio KPI browser so far, which exhibits the problem. The other client we need to test is Sharepoint 2007.

Can you share any insight about the rationale for SSAS work this way? In my Google I've seen numerous other people discussing this as a problem, so I hope MS seriously considers addressing it in a future release. We're trying very hard to stay query-tool agnostic in our designs - this definitely makes that more difficult.

Thanks,
Kevin|||

> In my Google I've seen numerous other people discussing this as a problem, so I hope MS seriously considers addressing it in a future release.

First, I do not use Google, I use Microsoft Live Search (www.live.com) instead. Subselects were originally designed to solve different class of problems, but the actual usage proved that people wanted to use them as more functionality rich WHERE clause, although we have tried to separate the functionalities of subselects and WHERE. This obviously didn't work out well, therefore SP2 brought many changes that made subselects and WHERE to be closer. It is correct to assume, that Microsoft seriously considers addressing this issue in the future release.

|||>First, I do not use Google, I use Microsoft Live Search
Naturally. But MS Live Search is so much harder to turn into a verb. ;)

>Microsoft seriously considers addressing this issue in the future release.

When you say "future release" - is this something that could theoretically be addressed in a service pack, were there sufficient demand? Or is it too significant a change for that, and we should expect to have to wait for the next full version of SSAS for a fix?

|||We never discuss the future plans or features that may be added in the future. All I said was that Microsoft is aware of the issue and seriously considers it. When and whether something will be done about it - is up to the product team, and will be disclosed through appropriate channels.|||

Thanks for the posting. I have been testing using both BIDS and the MOSS KPI webpart. For KPI's, BIDS implements an explicit CREATE SUBCUBE for slicing while Sharepoint 2007 seems to use an in-line subselect in the FROM clause to apply the selection from the filter webpart. In both cases a KPI based on a non-calculated measure works fine while any calculated measure based on a ParallelPeriod returns a null. Given the behavior in SP2 is there any available method for defining trend-type KPI's that depend on ParallelPeriod (or similar) functionality? Many of our KPI's depend on calculating the % change from the prior period.

Thanks

John

|||BIDS KPI browser is not end-user client tool, and therefore can be safely ignored here. As far MOSS KPI webpart, I suggest you report this issue to Sharepoint team, and ask them to use WHERE clause instead of subselect (or in addition to subselect if they choose so).|||

I have posted a question on the Sharepoint forum to ask about the KPI webpart.

As for BIDS, there's a point I don't understand. The profiler shows BIDS issuing a CREATE SUBCUBE statement as the slicer before the KPI query is excuted. We're using SQL Server 2005 SP2 and the updated BOL from December contains the following text in the description of the CREATE SUBCUBE statement:

"Also, explicit references to cells outside the subcube return cell values that are evaluated in the context of the whole cube. For example, you create a subcube that is limited to the current year. You then use the ParallelPeriod function to compare the current year to the previous year. The difference in values will be returned even though the previous year’s value lies outside the subcube."

Is this statement correct? Should a ParallelPeriod that defines a member outside the current context as specified by a CREATE SUBCUBE still return a value?

Thanks

|||Yes the statement in BOL is correct. The issue here is that subselect doesn't change current coordinate, so you are looking at ParallelPeriod of All member, which is NULL.

ParallelPeriod that never returns null

I'm sure this is easy, but I haven't been able to cook up the secret sauce: I need a function like ParallelPeriod that will always return a member (unless I'm asking for a member that predates the oldest member in the dimension, when null is perfectly fine).

For example, ParallelPeriod([Month],1,[2006].[December].[31]) returns null. Instead, I want to get back [2006].[November].[30] (the last day of the month).

What's the secret?

There are many ways to do it. One way is to have an attribute which keeps number of days needed to go back to get to the day in the previous month. Then you will use

Date.CurrentMember.Lag(Date.DaysToGoBack.MemberValue)

for December 30 it will be 30, and for December 31 it will be 31 - so both of them will land on November 30.

|||How 'bout a way that doesn't involve changing the definition of the cube?|||

Possible too, but it won't have as good performance as the solution I proposed first. Again, there are many ways, but they revolve around the following theme (note that the formula below is only valid for the Month level. I am not sure what you want to do on the other levels).

IIF(Date.CurrentMember IS Date.CurrentMember.Parent.LastChild, Date.CurrentMember.Parent.PrevMember.LastChild, ParallelPeriod(...))

|||

OK, I see the pattern. The solution you propose above won't quite work (think of March), but it's close enough to something that will work to see where to take it.

If I decide that I really need this function, I'll probably go with the first suggestion you made, since I can still change the cube design at this point, I was just looking for a wider variety of options.

Thanks for the suggestions!

Wednesday, March 21, 2012

ParallelPeriod MDX function not working

I created a calculated measure called [Previous Year Percent Rejected]. I used the following expression:

(ParallelPeriod([Year],1,[Time].[Time Hierarchy].CurrentMember),[Measures].[Percent Rejected])

The syntax checks out fine. However, when I try to use the calculation, I get an error message -- with a #VALUE! in the column.

The error message reads " The parallel period expression expects a level expression for the argument. A hierarchy expression was used."

I tried many different variations but I'm always receiving the same message. Any suggestions?

David

If you're using AS 2005, the problem could be that there is also an attribute hierarchy associated with [Year]. So, you could try fully specifying the [Year] level, like:

(ParallelPeriod([Time].[Time Hierarchy].[Year],1,[Time].[Time Hierarchy].CurrentMember),[Measures].[Percent Rejected])

|||

Thank you Deepak. Your solution fixed the problem.

David

ParallelPeriod Error

I keep getting an error "The ParallelPeriod function expects a member expression for the argument. A tuple set expression was used." Is there something that I can use instead of LastPeriods to get this to work?

Here is the trend expression for a KPI that I get the error for:

(KPIVALUE('ABI Aggregate Test')-(CoalesceEmpty(

Aggregate({[Entities].[SITE].&[1]}

* {[Entities].[EntityType].[Site]}

* {[TDVs].[Parameter - Material].&[Bitum_Coal_Usage_Site -]}

* {ParallelPeriod([Date].[Year - Quarter - Month - Date].[Date], 1,

LastPeriods(3, StrToMember('[TDV Result Date].[Year - Quarter - Month - Date].[Year].[Calendar ' + EssMdx.Ess.Epm.AnalysisServices.MdxFunctions.Timeframe.GetLastFullYear() + ']')))}

, [Measures].[Result]),0)))

Could you describe what you are trying to do? It looks like you are trying to go back 1 day from a set consisting of the last 3 years. If you are trying to compare the KPI value to the same day 3 years ago you could use the Lag() function instead of LastPeriods(), but I don't really think that is what you are trying to do.|||

Sorry, the above line {ParallelPeriod([Date].[Year - Quarter - Month - Date].[Date], 1, should be {ParallelPeriod([Date].[Year - Quarter - Month - Date].[Year], 1,

I am trying to get a trend expression based on 1 year back (or 2 or 3...). ParallelPeriod has been working fine except with date ranges. The KPI value expression will give me a value for the last 3 full years (2006, 2005, and 2004) and is the same expression without the ParallelPeriod function. If the trend is 1 year back then it should be 2005, 2004, and 2003 (or it may be 2003, 2002, 2001).

Thanks

|||

That makes a bit more sense. In this case you simply have the LastPeriods and ParallelPeriod function nested the wrong way around, changing it to the following should work. Basically you need to pass the result of your GetLastFullYear Function to ParallelPeriod() and then pass the member from that to LastPeriods.

eg

(KPIVALUE('ABI Aggregate Test')-(CoalesceEmpty(

Aggregate({[Entities].[SITE].&[1]}

* {[Entities].[EntityType].[Site]}

* {[TDVs].[Parameter - Material].&[Bitum_Coal_Usage_Site -]}

* {LastPeriods(3,
ParallelPeriod([Date].[Year - Quarter - Month - Date].[Date], 1,StrToMember('[TDV Result Date].[Year - Quarter - Month - Date].[Year].[Calendar ' + EssMdx.Ess.Epm.AnalysisServices.MdxFunctions.Timeframe.GetLastFullYear() + ']')))}

, [Measures].[Result]),0)))

|||Thanks.

Monday, March 12, 2012

Paging in sql 2005 using ROW_NUM()

It seems that Row_num() function does not works with Dynamic sql having if
blocks to check input parameters for null and sp_executesql t excute the
query...Please help me to find a necesasry solution..
Hari
Can yopu post sample data + an expected result to be tested?
"Hari" <Hari@.discussions.microsoft.com> wrote in message
news:8CE0B2A3-4347-4983-BD35-A2B502BFFD8D@.microsoft.com...
> It seems that Row_num() function does not works with Dynamic sql having if
> blocks to check input parameters for null and sp_executesql t excute the
> query...Please help me to find a necesasry solution..

Paging in sql 2005 using ROW_NUM()

It seems that Row_num() function does not works with Dynamic sql having if
blocks to check input parameters for null and sp_executesql t excute the
query...Please help me to find a necesasry solution..Hari
Can yopu post sample data + an expected result to be tested?
"Hari" <Hari@.discussions.microsoft.com> wrote in message
news:8CE0B2A3-4347-4983-BD35-A2B502BFFD8D@.microsoft.com...
> It seems that Row_num() function does not works with Dynamic sql having if
> blocks to check input parameters for null and sp_executesql t excute the
> query...Please help me to find a necesasry solution..|||Have you considered using key values rather than page numbers for paging?
Using key values is significantly faster than row numbering techniques can
ever be b/c each page query is simply an index range scan rather than having
to materialise row numbers in a result-set simply to work out which rows
make up page n. It also more accurately accounts for movements in the
underlying database.
Regards,
Greg Linwood
SQL Server MVP
http://blogs.sqlserver.org.au/blogs/greg_linwood
Benchmark your query performance
http://www.SQLBenchmarkPro.com
"Hari" <Hari@.discussions.microsoft.com> wrote in message
news:8CE0B2A3-4347-4983-BD35-A2B502BFFD8D@.microsoft.com...
> It seems that Row_num() function does not works with Dynamic sql having if
> blocks to check input parameters for null and sp_executesql t excute the
> query...Please help me to find a necesasry solution..

Paging in sql 2005 using ROW_NUM()

It seems that Row_num() function does not works with Dynamic sql having if
blocks to check input parameters for null and sp_executesql t excute the
query...Please help me to find a necesasry solution..Hari
Can yopu post sample data + an expected result to be tested?
"Hari" <Hari@.discussions.microsoft.com> wrote in message
news:8CE0B2A3-4347-4983-BD35-A2B502BFFD8D@.microsoft.com...
> It seems that Row_num() function does not works with Dynamic sql having if
> blocks to check input parameters for null and sp_executesql t excute the
> query...Please help me to find a necesasry solution..|||Have you considered using key values rather than page numbers for paging?
Using key values is significantly faster than row numbering techniques can
ever be b/c each page query is simply an index range scan rather than having
to materialise row numbers in a result-set simply to work out which rows
make up page n. It also more accurately accounts for movements in the
underlying database.
Regards,
Greg Linwood
SQL Server MVP
http://blogs.sqlserver.org.au/blogs/greg_linwood
Benchmark your query performance
http://www.SQLBenchmarkPro.com
"Hari" <Hari@.discussions.microsoft.com> wrote in message
news:8CE0B2A3-4347-4983-BD35-A2B502BFFD8D@.microsoft.com...
> It seems that Row_num() function does not works with Dynamic sql having if
> blocks to check input parameters for null and sp_executesql t excute the
> query...Please help me to find a necesasry solution..

Friday, March 9, 2012

Paging in MDX

Hi

I am new to mdx.i want to know can we implement paging in mdx query? is there any function in mdx so that i can return resultset based on count.i am using topcount function to return 10 rows.but i want to return result for next top 10 and so on.. in same query. like we do in paging.

Thanks in advance

There are probably ways of doing this, one that comes to mind would be to use a combination of topcount and tail

eg. page1... TopCount( <set>, <expression>, 10)

page2... TopCount( <set>, <expression>, 20).tail(10)

Monday, February 20, 2012

Page Number Needed in Report Header

I need to create a page number in a report header.

I wrote a function to calculate a number, however I do not know how to associate this with a new page event. How can this be handled and is there an easier way?

Here is my simple function:

Public Function getPageNumber(ByRef iPageNo As Integer) As Integer
Dim iNo as Integer
iNo = iNo + 1
Return iNo
End Function

Thanks,

cj

You can put the page number into a report header without using custom code.

Drop a textbox into the report header and use this expression:

=Globals!PageNumber

-Chris

|||

I don't think that will work because the "=Globals!PageNumber" only works in the Page Header, not the Report Header, correct?

I get this error:

The value expression for the textbox ‘textbox97’ refers to the global variable PageNumber or TotalPages. These global variables can be used only in the page header and page footer.

~cj