Multipe DataSet Values in one Row - sql-server

I have a Report in SSRS 2008 that looks like so:
For the Sales Attendees and Other Attendees it may have more than one person that needs to go in that row. As you can see from the screenshot right now it just creates another row. How would I make it so they go into the same row instead of creating new rows?
EDIT: I have to use FetchXML. I'm working against CRM 2011.
Thanks!

As Brent D mentions, I would rather do this in the data source, but you can do the same thing with the RunningValue function and some custom code. (Another blog entry using the same approach.)
Write the custom code to take in additional strings and add them to the end of a stored string. It will need a second parameter, so you know when to clear out the stored string and start over for the next group.
Once you've got this working, you can use this in a group footer, and then hide your data rows.

You could try concatenating the names with a comma in the sql datasource by doing something like:
Select <main data columns, e.g. RSM/NAM,AppointmentDate,etc>
,stuff((select ','+SalesAttendee From tableB Where TableA.ID=TableB.ID For XML Path('')),1,1,'')
From TableA
See SQL Concatenation for reference.

Related

SSRS - Multi Value Parameter Report Problem

I have a quite strange / unusual request for an SSRS report. The client wants to be able to paste in large lists of ID numbers from an Excel sheet column (normally < 100 values but can be as many as 20,000 + values) as a search parameter in the report.
Now, I know how to pass multi value parameters from SSRS to a stored proc etc, that's not the issue. The issue is with this requirement to literally paste in a list of IDs into the multi value parameter input box and then limit the dataset based on that list (rather than pre-populate the Multi Value parameter with a list of values based on a query / SP as you normally would)
My question is what would be the best method / approach to this problem as I have never had a similar ask in many years of SSIS development? I need to make the solution as "self-service" as possible too, so as easy as running an SSRS report from report manager ideally. I know I could just import the Excel data into a table in the database and join to that etc but ideally would like something the user can run without the need for any tech input to import data or run SQL through SSMS to get the datset.
When you copy/paste from excel its just a tab delimited string. You can configure a string parameter to allow multiple values, and then in the expression editor, split the string by tab values or by line breaks.
Here's how:
In the parameter properties check the 'Allow multiple values' checkbox on the
general tab
Then in the datasource properties click the 'fx' (expression) button next to the parameter on the parameters tab
In the expression editor that appears, type the following:
=replace(split(Parameters!MyParameter.Value,vbCrLf),"\x0009","")
This will split the string by line breaks, then strip the tab characters out. After that you can treat it like any multi-valued parameter.
If you have a typical multi-value parameter setup then you can just copy/paste the column from excel directly in, it will automatically put each cell row copied from excel on a new line.
So if your query looked something like
SELECT * FROM myTable WHERE EmployeeName IN(#empName)
and empName was you report parameter, if no available values are configured you'll get an empty list when you click in the parameter field, just copy paste direct from Excel and it will work.
I'm not sure if there would be any limits or how good performance would be especially if copying thousand of values but certainly for a reasonably small number of items this will work.
The only other way I can think of that means no real extra work for the user would be to have them drop the workbook into a specified folder (maybe with a subfolder based on their SSRS username, then use openrowset to read the contents either directly into a dataset or better still, into a permanent table with their username and the parameter value on each row.
The openrowset statement could sit at the top of your main dataset query
Then your query could do something simple like
DELETE FROM myParamValueTable WHERE UserName = #UserID
INSERT INTO myParamValueTable
SELECT * FROM (OPENROWSET .....) xl
SELECT * FROM myTable t
JOIN myParamValueTable p
ON t.EmployeeName = p.EmployeeName
WHERE p.UserName = #UserID

Iterative UPDATE loop in SQL Server

I would really like to find some kind of automation on this issue I am facing;
A client has had a database attached to their front end site for a few years now, and until this date has been inputting certain location information as a numeric code (i.e. County/State data).
They now would like to replace these values with their corresponding nvarchar values. (e.g Instead of having '8' in their County column, they want it to read 'Clermont County' etc etc for upwards of 90 separate entries).
I have been provided with a 2-column excel sheet, one with the old county numeric code and one with the text equivalent they request. I have imported this to a temp table, but cannot find a fast way of iteratively matching and updating these values.
I don't really want to write a 90 line CASE WHEN paragraph and type out each county name manually. Opens doors for human error etc.
Is there something much simpler I don't know about what I can do here?
I realize that it might be a bit late, but just in case someone else is searching and comes across this answer...
There are two ways to handle this: In Excel, or in SQL Server.
1. In Excel
Create a concatenated string in one of the available columns that meets your criteria, i.e.
=CONCATENATE("UPDATE some_table SET some_field = '",B2,"' WHERE some_field = ",A2)
You can then auto-fill this column all the way down the list, and thus get 90 different update statements which you can then copy and paste into a query window and run. Each one will say
UPDATE some_table SET some_field = 'MyCounty' WHERE some_field = X
Each one will be specific to a case; therefore, you can run them sequentially and get the desired result, or...
2. In SQL Server
If you can import the data to a table then all you need to do is write a simple query with a JOIN which handles the case, i.e.
UPDATE T1
SET T1.County_Name = T2.Name
FROM Some_Table T1 -- The original table to be updated
INNER JOIN List_Table T2 -- The imported table from an Excel spreadsheet
ON T1.CountyCode = T2.Code
;
In this case, Row 1 of your original Some_Table would be joined to the imported data by the County_Code, and would update the name field with the name from that same code in the imported data, which would give you the same result as the Excel option, minus a bit of typing.

Mule - Record cannot be mapped as it contains multiple columns with the same label

I need to do join query to MS SQL Server 2014 DB based on a column name value. The same query runs when doing query directly to DB, but when doing query through Mule I'm getting error. The query looks something like this :
SELECT * FROM sch.emple JOIN sch.dept on sch.emple.empid = sch.dept.empid;
The above query work fine while doing query directly to MS SQL Server DB, but gives the following error through mulesoft.
Record cannot be mapped as it contains multiple columns with the same label. Define column aliases to solve this problem (java.lang.IllegalArgumentException). Message payload is of type: String
Request you to please help me out.
Specify columns list directly:
SELECT e.<col1>, e.<col2>, ...., d.<col1>,...
FROM sch.emple AS e
JOIN sch.dept AS d
ON e.empid = d.empid;
Remarks:
You could use aliases instead of schema.table_name
SELECT * in production code in 95% cases is bad practice
The column that has duplicate is empid(or more). You could add alias for it e.empid AS emple_empid and d.empid AS dept_empid or just specify e.empid once.
To avoid specifying all columns manually, you could drag and drop them from object explorer to query pane like Drag and Drop Column List into query window.
Second way is to use plugin like Redgate Prompt to expand SELECT *:
Image from: https://www.simple-talk.com/sql/sql-tools/sql-server-intellisense-vs.-red-gate-sql-prompt/
Addendum
But the same query works directly.
It works because you don't bind them. Please read carefully link I provided for SELECT * antipattern and especially:
Binding Problems
When you SELECT *, it's possible to retrieve two columns of the same name from two different tables. This can
often crash your data consumer. Imagine a query that joins two
tables, both of which contain a column called "ID". How would a
consumer know which was which? SELECT * can also confuse views (at
least in some versions SQL Server) when underlying table structures
change -- the view is not rebuilt, and the data which comes back can
be nonsense. And the worst part of it is that you can take care
to name your columns whatever you want, but the next guy who comes
along might have no way of knowing that he has to worry about adding a
column which will collide with your already-developed names.
But the same query works directly.
by Dave Markle

query views code (definitions)

I am trying to find some views which have a comment in them - in the code! - (something like '--TO DO'), but the problem is that I don't know the views names and to look at each by hand would take me a whole lot of time (I have over 2k views).
So I am trying to make a query that will search in the view's code for the text of interest.
I managed to come up with something like this:
SELECT *
FROM ALL_SOURCE
WHERE UPPER(text) LIKE UPPER('%my_text_here%')
ORDER BY name desc
But this doesn't query my views. It queries the functions, the procedures, packages, triggers...pretty much everything except the views...which I find pretty odd.
At first I thought that maybe there were no views that contained that keyword so I changed to some basic SQL keywords that I knew for sure exist...and still no results.
Anyone could tell me what am I missing/doing wrong?
Thanks!
The views are stored in all_views (also: dba_views or user_views, depending on your access and needs). However, the text column in all_views is a long, which means you'll first have to convert it to a Clob before you can use it in your query. The easiest work around (from Tom Kyte) would be to create a new table in your schema and convert the Longs into Clobs like this:
create table myviews as
select owner, view_name, to_lob(text) as text from all_views;
Then select from your own table:
select *
from myviews
where upper(text) like upper('%my_text_here%')
order by view_name desc;

Appending an ADO.Net Datasource in winforms

I am working with two seperate SQL statements when user conducts a search on my winforms app.
A user can search based on an OrderNumber, OrderDate, ClaimNumber, ClaimDate, CustomerID, CustomerPhone
One SQL statement returns the OrderNumber (in case the user searched based on OrderDate), which is used to execute another SQL statement, which returns the details about the order.
The results are populated in a gridview.
Once the first statement is executed, I have a DataSource (DataSet). How can I append that datasource to display the fields from the second statement as well, keeping in mind, that the first statement could return multiple records, all of which will need to have the appropriate order details correctly linked.
Any ideas / suggestions?
SQLDataSet? Is this a custom structure? It's not a .net structure is it?
If you are referring to .net DataSet you can use the Merge method to merge 2 datasets.

Resources