does SSRS have a limit on number of fields in the dataset? - sql

I have a data set:
select * from table1 --approximately 100 fields
join table2
on...
join table3
on...
The query works when I test it in SSMS.
However, when I try to run a report with this query as the dataset, I am getting:
I thought that perhaps I'm incorrectly capturing the names of the fields, so instead of doing select * i did select field1, field2...field100 but still getting the same result.
What am I doing wrong?
Please note that I have indeed made sure that all the field names are unique by doing a unique filter in excel.

I ran into the same problem. This was my solution.
1)First test your Reporting boundaries, try to determine the maximum amount of fields you can display.
2)Take your main report and make it a sub report.
3)Pass the remaining values through parameters as a concatenated string
4)Use your new sub-report to parse the parameters string.
Here is some VB code to help. Paste this in your report properties cod section.
'***************************************************************************************************************************
Public Function ListToString(myList As String, Delimiter As String, Optional index As Integer = 0) As String
'-----------------------------------------------------------------------------------
'Purpose:
'----This function splits a list and allows one to access the split list like a programmable array
'Description:
'----Input:
'--------myList: String containing the list created in SSRS
'--------Delimiter: what you used to seperate/ delimit each element
'--------index: the index you want you access
'----Output:
'--------ReturnString: returns Name in the format of "FirstName LastName"
'Version Control log: (Date - Name: Description)
'----xx/xx/xxxx Adrian Williams Creation of function
'-----------------------------------------------------------------------------------
Dim returnString As String = ""
Dim myArray As String()
myArray = myList.split(delimiter)
returnString = trim(myArray(index))
Return returnString
End Function
'***************************************************************************************************************************

Related

Chinese characters in Access SQL Query

After populating the recordsource the next action is clicking on one of the fields populated to "activate" the record. When clicking this, the goal is that the SEC_ID (A GUID, Number Data Type) is stored as a tempvar and used in future queries. This GUID is also placed in a text box just for a visual debug. However it doesn't put the GUID, it puts random Chinese characters. I've tried to place it into a MsgBox just to also see and it spits out "???????".
My code to populate the rowsource:
Dim componentListSQL As String
If FCSUtilities.AssessmentUoM = "Metric" Then
componentListSQL = "SELECT DISTINCT [100b_Working].SEC_SYS_COMP_ID, [100b_Working].SEC_ID, [110b_RO_Material_Category].MAT_CAT_DESC, [110b_RO_Component_Type].COMP_TYPE_DESC, [110b_RO_Material_Category].MAT_CAT_ID, [110b_RO_Component_Type].COMP_TYPE_ID, [100b_Working].ID_Number, [100b_Working].Model, [100b_Working].Serial_Number, [100b_Working].Capacity, [100b_Working].Manufacturer, [100b_Working].SEC_YEAR_BUILT, ROUND([100b_Working].SEC_QTY, 0) AS SEC_QTY, [100b_Working].UOM_MET_UNIT_ABBR, [100b_Working].UOM_ENG_UNIT_ABBR, [100b_Working].Equipment_Make, [100b_Working].UOM_CONV " _
& "FROM (110b_RO_Units_Conversion INNER JOIN (110b_RO_Component_Type INNER JOIN (110b_RO_Material_Category INNER JOIN 110b_RO_CMC ON [110b_RO_Material_Category].MAT_CAT_ID = [110b_RO_CMC].CMC_MCAT_LINK) ON [110b_RO_Component_Type].COMP_TYPE_ID = [110b_RO_CMC].CMC_CTYPE_LINK) ON [110b_RO_Units_Conversion].UOM_ID = [110b_RO_CMC].CMC_UoM) INNER JOIN 100b_Working ON [110b_RO_CMC].CMC_ID = [100b_Working].SEC_CMC_LINK " _
& "WHERE ((([100b_Working].SEC_SYS_COMP_ID) = [Forms]![200a_MainWindow]![txtDebugCompSysID]) And (([100b_Working].SEC_ID) Is Not Null)) " _
& "ORDER BY [110b_RO_Component_Type].COMP_TYPE_DESC;"
Me![210_ComponentList].Form.RecordSource = componentListSQL
End If
The OnClick event:
Private Sub txtMaterialCategory_Click()
Me.txtActiveSecID.Value = Me.txtSecID.Value
End Sub
The txtSecID appears as a GUID as it should but it's in the txtActiveSecID that it becomes Chinese characters even if I attempt to put it as a tempvar then set it into the txtActiveSecID.
I'm not exactly sure what is going on. Looking at different stacks, it points that it's due to long/memo field but as I said previously, the SEC_ID field data type is Number.
Per MS documentation https://learn.microsoft.com/en-us/office/vba/api/Access.Application.StringFromGUID:
The Microsoft Access database engine stores GUIDs as arrays of type Byte. However, Access can't return Byte data from a control on a form or report. To return the value of a GUID from a control, you must convert it to a string. To convert a GUID to a string, use the StringFromGUID function. To convert a string back to a GUID, use the GUIDFromString function.
StringFromGUID(Me.txtSecID.Value)
However that results in output like:
{guid {2786C27B-CB7C-4DEA-8340-1338532742DE}}
That should still work as filter critera but could do further processing to extract GUID from that string. Use string manipulation functions to remove the {guid header and trailing }. Review Access - GUID value stored in textbox, can't be used in SELECT statements

Rowfilter Select syntax using a value stored in a variable

I am using VB.NET and I need to use Datatable.Select to get a row which has a matching value.
Consider I have Datatable_A, which has many rows. I am interested to get row/rows which matches my search criteria. In this case, I must get a row (RowA), which has AnswerA stored in Column_A.
I know I can easily use the method below to find the answer:
RowA = Datatable_A.Select("Column_A = 'AnswerA'")
However, value 'AnswerA' is stored in Variable_A.
I have tried using
RowA = Datatable_A.Select("Column_A = 'Variable_A'")
Unfortunately, I still could not get the datarow, whose Column_A = 'Answer A'.
I have studied the explanation in this website DataView RowFilter Syntax [C#], but I could not find any clue there.
Thank you.
If you want to select a subset of your datatable rows using the Select method and a variable that contains the value to filter your rows you need to write
Dim Variable_A = "MySearchCriteria"
Dim rowsSelected = Datatable_A.Select("Column_A = '" & Variable_A & "'")
This means that you want all the rows in which the Column_A (a string column) contains exactly the value "MySearchCriteria" stored in the Variable_A. The filter condition is created concatenating the literal string describing the name of the column and the operator with the content of the Variable_A. Since Column_A is assumed to be a string column then you need to encapsulate the Variable_A between single quotes.
And remember that Select returns an array of DataRow that match the filter expression.
For Each row in rowsSelected
Console.WriteLine(row("Column_A").ToString)
Next

SSRS Format a multi-value field

I have a number field in my ssrs report that has multiple values separated by a comma. I want to convert the number to currency but I get an error when the field has more than on value. I'm converting the text box to currency and added the (*) operator to multiply by .01 so my numbers are not inflated. I'm sure the comma is what causing the error as BIDS is expecting a number, but I'm not sure how to write the expression so that it only modifies the numbers in the string.
=Fields!field_A.Value * .01
Field
Number1 = converts to currency($Number1)
Number1, Number2 = #Error
number1, number2, number3 = #error
You can use embedded code in the report to do the processing of the string. This allows you to use the full VB.NET language. From the report menu in SSRS select Report Properties and select the Code section on the left. (This is in VS2010, I'm not sure what version of SSRS you're building in.)
Then you can use a VB.NET function like the one below to do the actual string processing. I'm not sure exactly how you want the output so you'll want to read the MSDN page on the FormatNumber() VB.NET function.
Function ConvertCashString(orig As String)
Dim newString As String = ""
For Each s As String In orig.Split(",")
Dim parsedString As Double
If (Double.TryParse(s, parsedString)) Then
newString += "$" + FormatNumber(parsedString * 0.01, 2, TriState.True, TriState.UseDefault, TriState.False) + ", "
End If
Next
Return newString
End Function
Then in the report itself you can call the function like so:
=Code.ConvertCashString(Fields!dbString.Value)
You should also read the MSDN page: Add Code to a Report (SSRS)

vb.net DAL Specify columns returned

I have a Data Access Layer class that has a method (GetPeople) that will retrieve records from a SQL Server table (people). This table has more than 20 fields, including varbinary type.
Right now, SQL query is something like
SELECT * FROM people
From my BLL class, I will call DAL.GetPeople(), which will return all columns.
What would be the best way to specify which columns to return, so I could improve performance? For example, sometimes I would like to return all fields, other times, just one or two.
UPDATE
To explain it better:
In DAL I have a method GetPeople() which calls a SQL Server function GetPeople.
In BLL I have a method GetPeople() which calls DAL.GetPeople(), after doing some business logic.
In my presentation layer, I call BLL.GetPeople().
This is working, but on SQL function, I have "SELECT * FROM people". Sometimes I would like to retrieve only one column (eg. name) from table, but in this case all columns are returned, which I think is affects performance.
So, I would like to have a kind of dynamic SELECT query on this SQL Server function, whose columns returned would depend on how I call the function...
I think you are after something like this where you can pass in a comma-seperated list of column names
Private Function GenerateQuery(ByVal columnNames As String) As String
' columnNames in the following format 'column1,column2,column3'
Dim lstColumnNames As String() = Split(columnNames, ",")
Dim strSQL As New StringBuilder
strSQL.Append("SELECT ")
For intColNumber As Integer = 0 To lstColumnNames.GetUpperBound(0)
strSQL.Append("[")
strSQL.Append(lstColumnNames(intColNumber))
strSQL.Append("]")
If intColNumber < lstColumnNames.GetUpperBound(0) Then
strSQL.Append(", ")
End If
Next
strSQL.Append(" FROM People ")
Return strSQL.ToString
End Function
You can use it like this: SqlCommand.CommandText = GenerateQuery("column1,column2,column3")
The column names are wrapped in [] symbols so you don't have to worry about reserved words causing the database to error.
Change your SQL-query to something like
SELECT column1, column2, column3 FROM people;
EDIT:
What you are going to need to do is create function that will put your SQL string together for you. When i did this before, I had all of the available fields in a checked-list control, and if i wanted them pulled, I checked them. The checked items were then put through the function to assemble the string. It should be pretty simple since there are not any joins going on.

How do i obtain foreign table field using string value for fieldname with reflection and entity framework

I have 2 tables. An asset table that links using a foreign key to a device table.
To get the device_name field of the asset, in linq i would use:
dim device as string = result.device.device_name
The Result object contains the unique record from an earlier linq to entity framework command.
Now I have a need to allow end users to specify their fields they want in a report. I will end up having a string name of the field, so tried using reflection
dim name as string = result.GetType().GetProperty("asset_name").GetValue(result)
This returns the asset_name field so i thought great, i should be able to get the relating foreign table field value.
dim device = result.GetType().GetProperty("device").GetValue(result).GetType.GetProperty("device_name").GetValue(result.device)
This works however i had to specify the object. As i will have other tables linking to the first table, would i have to write additional code to check what object and manually specify? Or am i going into this wrongly? Any help and advice appreciated.
I couldn't find a cleaner solution, so this is how i did it:
dim field as string ="device.device_name"
dim output as string =""
dim subtable as string =""
If field.Contains(".") Then
subtable = field.Substring(0, field.IndexOf("."))
field = field.Substring(field.IndexOf(".") + 1)
End If
If subtable <> "" Then
Select case subtable
Case "device"
If Not IsNothing(result.device.GetType().GetProperty(field)) Then
output = result.device.GetType().GetProperty(field).GetValue(result.device)
End If
End Select
Else
If Not IsNothing(result.GetType().GetProperty(field)) Then
output= result.GetType().GetProperty(field).GetValue(reult)
End If
End If
Return output