Friday, March 23, 2012
How to determine default values of a field during runtime
properties of
each field in a recordset (SQL server) and all is working well. My
problem is that I
dont know how to find the default value of a field from the table. Does
anyone have
any code suggestions that would get me the default value
For Each F In rstProgressData.Fields
If F.Type <> adChapter Then
If F.Name <> "upsize_ts" Then
rstDest.AddNew
rstDest!Progress = F.Name
Select Case F.Type
Case adChar, adVarWChar, adVarChar
rstDest!ProgressFieldType = "String"
rstDest!ProgressFieldSize = F.DefinedSize
Case adBoolean
rstDest!ProgressFieldType = "Boolean"
Case adSmallInt, adUnsignedTinyInt, adInteger
rstDest!ProgressFieldType = "Integer"
Case adDecimal, adNumeric
rstDest!ProgressFieldType = "Decimal"
Case adDBTimeStamp
rstDest!ProgressFieldType = "DateTime"
Case 203
rstDest!ProgressFieldType = "Memo"
End Select
If (F.Attributes And adFldIsNullable) = adFldIsNullable Then
rstDest!ProgressFieldNullable = True
End If
rstDest.Update
End If
End If
Next FThats hard to see where your recordset is based on if you don=B4t send
the query with you, but otherwise the information can be queried
through the INFORMATION_SCHEMA Views:
Select Column_default from INFORMATION_SCHEMA.COLUMNS
Where table_name =3D '<SomeTable>'
HTH, Jens Suessmeyer.|||The code has to be generic so that it can deal with any sql statement.
As above for any query I can get the field size, type, name & if its
nullable, I just need to find out what syntax to use to get the default
value e.g F.Type gives me type. F has been defined as an ADODB.Field.sql
How to determine Count of ties in MDX?
I need to determine the number of values in a set that are non-unique in the set.
In SQL, I would do the following:
select sum(value_count) as Ties
from (select value, count(*) as value_count
from source
group by value
having count(*) >1
)
In MDX, I have a set defined in a query that is passed into several custom statistical functions. I would like to be able to accomplish this without writing another external function, as it seems the sort of thing that should be easy...
Here is the query I'm trying to plug this into. Suggestions welcome.
with
set [data] as ( nonempty({
[Sample Date].[Time].[Day] }) *{ [Measures].[Parm Value] } )
MEMBER [Sen's Slope] as 'Statistics.Sen_Slope({[data]})'
MEMBER [Kendall's Tau] as 'Statistics.KENDALLS_TAU({[data]})'
MEMBER [Significant] as 'Statistics.Significance({[data]})'
MEMBER [MK_Z] as 'Statistics.Mann_Kendall_Z({[data]})'
member [measures].[Samples] as [data].count
member [measures].[Average] as avg([data])
member [measures].[Median] as Median([data])
member [measures].[Last Sample] as tail([data],1).item(0)
MEMBER [Ties] as '0'
select {[Samples],[Average],[Median],[Last Sample], [Kendall's Tau], [Sen's Slope], [MK_Z], [Significant], [Ties] } on 0
FROM ( SELECT ( [Sample Date].[Time].[2002 Q4]:[Sample Date].[Time].[2006 Q3] ) on 0,
{([Site Hierarchy].[Site Hierarchy].[Site ID].[0829SD6001] ,
[Analysis Parameter].[Analysis Parameter].[Acidity (ACD)])} ON 1
FROM [Sample Data])
;
Hi Clayton,
This sample from Adventure Works, where value is [Reseller Order Quantity], seems to work:
SQL query:
>>
select sum(order_count) as Ties
from
(select OrderQuantity, count(*) as order_count
from
(select ProductKey, sum(OrderQuantity) as OrderQuantity
from dbo.FactResellerSales
group by ProductKey) ps
group by OrderQuantity
having count(*) > 1) oc
87
>>
MDX query:
>>
With
Member [Measures].[PrdTies] as
Count(Filter(Order(NonEmpty(
[Product].[Product].[Product].Members,
{[Measures].[Reseller Order Quantity]}),
[Measures].[Reseller Order Quantity], BDESC) as OrdPrds,
(OrdPrds.CurrentOrdinal < OrdPrds.Count
And [Measures].[Reseller Order Quantity] =
([Measures].[Reseller Order Quantity],
OrdPrds.Item(OrdPrds.CurrentOrdinal)))
OR (OrdPrds.CurrentOrdinal > 1
And [Measures].[Reseller Order Quantity] =
([Measures].[Reseller Order Quantity],
OrdPrds.Item(OrdPrds.CurrentOrdinal-2)))))
select {[Measures].[PrdTies]} on 0
from [Adventure Works]
PrdTies
87
>>
|||
Deepak,
Thanks for the thourough response. I've done some testing, comparing results from the MDX you wrote to the ADOMD CLR proc I wrote, and I was getting different results. I've traced through the CLR version and manually counted the values in the set, and the CLR proc was correct. I've clipped out the relevant code in case you want to compare results. It may be the differences in how I'm calling the CLR functions by passing in a set versus the Measure method, which is working over the complete set of data from the subcube query.
Here is your test MDX query, with a measure added for the CLR function. In this case, both methods return the same count, as expected. I'm just curious as to what might be causing me to get dfferent counts between the two methods when used in my cube...
With
set [data] as ( NonEmpty([Product].[Product].[Product].Members)
*([Measures].[Reseller Order Quantity]) )
member [CountOfTies] as 'Statistics.CountOfTies({[data]})'
Member [Measures].[PrdTies] as
Count(Filter(Order(NonEmpty(
[Product].[Product].[Product].Members,
{[Measures].[Reseller Order Quantity]}),
[Measures].[Reseller Order Quantity], BDESC) as OrdPrds,
(OrdPrds.CurrentOrdinal < OrdPrds.Count
And [Measures].[Reseller Order Quantity] =
([Measures].[Reseller Order Quantity],
OrdPrds.Item(OrdPrds.CurrentOrdinal)))
OR (OrdPrds.CurrentOrdinal > 1
And [Measures].[Reseller Order Quantity] =
([Measures].[Reseller Order Quantity],
OrdPrds.Item(OrdPrds.CurrentOrdinal-2)))))
select {[Measures].[PrdTies], [CountOfTies]} on 0
from [Adventure Works];
Assembly code:
using System;
using System.Collections;
using Microsoft.AnalysisServices;
using Microsoft.AnalysisServices.AdomdServer;
namespace Statistics
{
public sealed class Statistics
{
private Statistics()
{
}
[CLSCompliant(false)]
// function to return a sum of the counts for tied values
public static Object CountOfTies(Set data1)
{
try
{
//number of Tuples in the set
Int32 v = data1.Tuples.Count;
if (v > 1)
{
//dimension a new array to hold values for passing into GetCountOfTies()
Double[] ValueArray;
ValueArray = new Double[v];
MDXValue mdxval;
Int32 i = 0;
// convert tuple set into an array
foreach (Tuple t in data1.Tuples)
{
mdxval = t;
ValueArray[i++] = mdxval.ToDouble();
}
// get array of any ties
Int32[] ResultArray = GetCountOfTies(ValueArray);
//sum counts to get results to return
i = 0;
foreach (Int32 j in ResultArray)
{i = i + j;}
return i;
}
else {return 0;}
}
catch (Exception e)
{
Console.WriteLine(e);
return "ERROR";
}
}
private static Int32[] GetCountOfTies(double[] doubleArray)
{
//create an array of counts of unique values, where there are ties in values.
//the resulting array will contain one element for each value with ties.
Array.Sort(doubleArray);
ArrayList numbers = new ArrayList();
double? lastVal = null;
int currentCount = 0;
foreach (double val in doubleArray)
{
if (lastVal != null && lastVal != val)
{
if (currentCount > 1)
numbers.Add(currentCount);
currentCount = 1;
}
else
{currentCount++;}
lastVal = val;
}
return (Int32[])numbers.ToArray(typeof(Int32));
}
}
}
Sunday, February 19, 2012
How to defne a globale variable in the report
I want's to define some global contant variable which contains some values
Like Name="Abc"
Age=123
Date=12/12/2006
How can i define it on sql server reporting serices report and access it value to assign on some fields?
You could use hidden parameters with default values I guess.
1 - Add a parameter to your report and set it to the correct type (string / number etc) and mark it as hidden
2 - Set the default value that you want for it
3 - In your report, access it with something like "=Parameters!theParameter.Value"
Regards Andreas
|||On the report properties, click on the Code tab and define it there, e.g.
Public Dim Age as Integer = 123
Then, you can reference it in the report as =Code.Age
|||Which approach will be best for performance?
Can anybody give the pros and cons of the both approaches .
|||If you want to be able to change the defined variables when calling a report it's good to have them as parameters. Lets say you programatically calls the report because you want to render a report in a WinForms app or something and want to be able to set the parameters from the winForms app, then the hidden parameter way is a good way I guess.
Otherwise, I suggest you do as Teo says.
Regards Andreas
|||
hi,
but parameters are readonly.
You cant set them through your custom code.
hemant
How to defne a globale variable in the report
I want's to define some global contant variable which contains some values
Like Name="Abc"
Age=123
Date=12/12/2006
How can i define it on sql server reporting serices report and access it value to assign on some fields?
You could use hidden parameters with default values I guess.
1 - Add a parameter to your report and set it to the correct type (string / number etc) and mark it as hidden
2 - Set the default value that you want for it
3 - In your report, access it with something like "=Parameters!theParameter.Value"
Regards Andreas
|||On the report properties, click on the Code tab and define it there, e.g.
Public Dim Age as Integer = 123
Then, you can reference it in the report as =Code.Age
|||Which approach will be best for performance?
Can anybody give the pros and cons of the both approaches .
|||If you want to be able to change the defined variables when calling a report it's good to have them as parameters. Lets say you programatically calls the report because you want to render a report in a WinForms app or something and want to be able to set the parameters from the winForms app, then the hidden parameter way is a good way I guess.
Otherwise, I suggest you do as Teo says.
Regards Andreas
|||
hi,
but parameters are readonly.
You cant set them through your custom code.
hemant
How to define a parameter to show the true values for any of 35 different products?
My boss database is in a way that customers might have baught any of the 35 products of the company. Say if they have bought product# 16, and 27, these two values are true for that customer and the rest are false (the table has 36 columns: 35 for products and 1 for customer ID). How can I show if a customer has bought anything at all (some of them has not bought anything), and if so which numbers as a parameter? I mean I want to have a parameter that user defines to see the result for customers who have number 10, 17 as true? or number 6 as false? I probably need two parameters, one for true and false and one for the number. Although I think if I have just one parameter, that might work too. Let's say the user checks numbers 5,9, and 14 and see the customers who have bought those. So my drop down should have 35 rows for the user to choose from. But how can I make this parameter to work (define wise or query wise)?
Thanks.
I am still stuck on this. Can you people (lots of experts here) help me on this?
Lots of thanks,
Alexan
|||Its really confusing your question anyway can u explain clearly
You need to Hide some records right?
|||
Thanks for answering Kiran.
Ok. Here is how it goes. We have a table in our database that holds the records for different products. I am going to scale down from 35 to 3 just for making the question easier. Here is how it is:
I have a table with these columns:
- Customer (Holds customer name string)
- Bought Product 1? (Holds Yes or No, indicating if this customer has bought Product 1)
- Bought Product 2? (Holds Yes or No, indicating if this customer has bought Product 2)
- Bought Product 3? (Holds Yes or No, indicating if this customer has bought Product 3)
Now I want to have a parameter so the user can choose to see only the customers who have bought product numbers passed by the parameter.
e.g. The user only wants to see which customers have bought Product 1 & 3, Or which customers have not bought product 1.
I hope this clarifies a little. Please if you still need some more clarification, send a post and I'll be explain more with details.
Waiting to hear from you guys.
I am new in databases and MS SQL, so Could you please help me out?
Lots of thanks,
|||Help please|||
Hi, ok assuming that you have SQL Server 2005 which holds the multivalue parameter and under the assumption your table structure is simplified as follows:
OrderDetail
========
Orderid
PosId
ProductId
Order
====
OrderId
CustomerID
You would have to do a Query like the following:
SELECT CustomerID From Order O
INNER JOIN OderDetail Od
ON O.OrderID = Od.OrderID
WHERE ProductID IN (@.YourParameter)
For the customername you would have to join additionally the Customer table to retrieve this data.
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
how to define a parameter in reporting services to choose to show/hide not null/null values?
Hi All,
I am using SQL Server Reporting Services 2005 and in my report I want to create a parameter called "hasEmail" with 3 possible values (Yes, No, Both) to show/ hide the customers who have/don't have emails or both.
Can anyone please help?
Try Add Parameter-Choose Available Values-Non queried- there you can put in the label and values that you want to return (Yes,No,Both) Then you will have to use these parameters to filter your dataset. Hope that helps.|||You said : "Then you will have to use these parameters to filter your dataset."
The problem is the parameter doesn't exactly match the field. For example, it's not like the case that: OK the parameter chosen by user is "Bicycles" so only show me the data (WHERE the param is Bicycle). The problem I have is that some of the customers have provided their emails in the database and some haven't. I want to be able to show (or not show) the customers that have (or have not) email address. Maybe I should use "EXISTS" or something, because like I said it's not a matter of exactly matching the string (bicycle for example) with the field; It's a matter of true/false if the email exists or not.
I don't know.
Any thoughts?
|||
Yes, right click table or list- if thats what you are using - properties- filters- I don't know about your particular case but here is one that I used a parameter to filter in- same concept, but how to apply to your case I'm not sure- you'll have to play with it.
(Expression)=Fields!CONT_FREQ_CODE.Value
(Operand) =
(Value) =iif(Format(Parameters!Report_Parameter_0.value,"MM")=3 or Format(Parameters!Report_Parameter_0.value,"MM")=6 or Format(Parameters!Report_Parameter_0.value,"MM")=9 or Format(Parameters!Report_Parameter_0.value,"MM")=12,Fields!CONT_FREQ_CODE.Value,"M")
|||
Thanks Kimberly,
I found my answer at
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=494455&SiteID=1
Thank you anyway.
how to define a parameter in reporting services to choose to show/hide not null/null values?
I am using SQL Server Reporting Services 2005 and in my report I want to create a parameter called "hasEmail" with 3 possible values (Yes, No, Both) to show/hide the customers who have/don't have emails or both.
Can anyone please help?
Try using a filter with the following entries. This assumes that there is an "Email" field of type string in the data set you are using, and the parameter name with the three values is ShowOnlyWithEmail. We use Len instead of IIF and a check for Nothing, because =IIF(IsNothing(Fields!Email.Value), 0, Fields!Email.Value.Length) will throw an exception if the field value is Nothing (IIF is a function and all arguments are evaluated before the function call), and Len will return 0 if the field value is Nothing.If the parameter is set to "Yes", then the first filter entry will
remove any rows that do not have an email address and the second will
not filter any rows.
If the parameter is set to "No", the the first filter entry will not
filter any rows, and the second will filter all rows with a length less
than 1.
If the parameter is set to "Both", then both filter entries will not filter any rows.
Ian|||It works fine. Thank you. What does LEN stand for? (Like REM is remove).|||Len is a function from VB to determine the length of an string (or size of any object) that does not blow up if a null value is passed in.
how to define a parameter in reporting services to choose to show/hide not null/null values?
I am using SQL Server Reporting Services 2005 and in my report I want to create a parameter called "hasEmail" with 3 possible values (Yes, No, Both) to show/hide the customers who have/don't have emails or both.
Can anyone please help?
Try using a filter with the following entries. This assumes that there is an "Email" field of type string in the data set you are using, and the parameter name with the three values is ShowOnlyWithEmail. We use Len instead of IIF and a check for Nothing, because =IIF(IsNothing(Fields!Email.Value), 0, Fields!Email.Value.Length) will throw an exception if the field value is Nothing (IIF is a function and all arguments are evaluated before the function call), and Len will return 0 if the field value is Nothing.If the parameter is set to "Yes", then the first filter entry will remove any rows that do not have an email address and the second will not filter any rows.
If the parameter is set to "No", the the first filter entry will not filter any rows, and the second will filter all rows with a length less than 1.
If the parameter is set to "Both", then both filter entries will not filter any rows.
Ian|||It works fine. Thank you. What does LEN stand for? (Like REM is remove).|||Len is a function from VB to determine the length of an string (or size of any object) that does not blow up if a null value is passed in.