SSRS Execute and display data created by TSQL - tsql

I have a TSQL scrip that populates coordinates as a table variable:
declare #reg_data table
(
I int NOT NULL PRIMARY KEY IDENTITY,
X float,
Y float
)
insert into #reg_data
select field1, dbo.func(field1) from table Y where ...
In SSRS 2008 how can I plot Y vs. X in a chart with another dataset?

You can only use one dataset in a chart in SSRS 2008. You'll need to create a dataset that combines X and Y first. Create a stored procedure that sets up your table variable and then use the code for your second dataset there to return a single dataset with both X and Y.

Related

combine two columns and create one in ADF

as a step to create my dimensional data model I need to combine two columns and create one new referencing to the units of values from each columns.
I have among other tables one table that has yearly GDP of a country. the table has two columns GDP represented as MONEY (unit) and the other year change (% as unit). in my fact table I would like to have both in same column but with a new columns representing dimension (units). because of that I am wondering how to merge these two columns and create another one that would specify if the value comes from the column with units (%) or (money). this applies to other entities in the data model that can have different units for same variable.
thanks for your help!
Consider orginal data format :
enter image description here
We have quartal dates a series of economic indicator and their values, on the right side there is another table with dimensions of the economic indicator.
What I need is to change data so it should be like this (fact table with quartal date granularity) :
enter image description here
I have reproduced the above scenario with a sample data and able to combine the columns like below.
My sample data of two columns Money and Unit:
Use derived column transformation for the res column which will have the Unit or Money values. To know which column value, I have used another column which_value.
Expression for res column:
iif(isNull(Money),Unit,Money)
Expression for which_value column:
iif(isNull(Money), 'Unit', 'Money')
Result in Data preview:

Multiplying 2 Columns in Sum Function giving an error in Crystal Formula Shop?

SAP Crystal Formula Workshop detecting the error when I am trying to multiply two columns inside the SUM function. However, my logic is working absolutely fine in MS SQL. Following is my SQL Code:
select Sum(Qty * Type) from Movements
Where, type could be '1' or '-1'. I am using this statement to get the Balance. Following is my formula inside the crystal report formula shop which is giving an error:
SUM({MovementReport;1.Qty} * {MovementReport;1.Type})
Is there any other way to do it?
You have to create a separate formula field that multiplies the two columns:
{MovementReport;1.Qty} * {MovementReport;1.Type}
and then calculate the sum of that formula field:
SUM({#YourNewFormula})

How to create a crosstable showing descriptive statistics in PostgreSQL?

I have a table contains data of year and value. I'd like to create a cross table with all the year as column headings and calculate descriptive statistics in the rows.
For instance, I'd like to calculate the mean and median value for year 2005, 2006, and 2007 separately and put them in the following table format.
2005 2006 2007
Median
Mean
To calculate the median and mean for year 2005, the code would be:
SELECT avg(vallue),percentile_cont(0.5) WITHIN GROUP (ORDER BY value)
FROM tablename WHERE year=2005;
but I don't know how to turn it into a table
in postgres "crosstab" is extension for pivot tables
for median I used this aggregate function and it was quite effective (fast and precise)

Is it possible to add custom calculated row in table?

My data source is Excel file. I imported the Excel file in a tableau. I want to create custom calculated row field for each column.
In the above picture, I can generate Grand Total in tableau from here Analysis -> Totals -> Show column grand totals. My problem is I want to generate another row which will have value from sum of High + medium row values.
Note: I taken this screenshot from excel sheet and please ignore the values in the row.
You can create a calculated field to sum just the High and Low values. Something like:
sum(If [Priority] = 'High' or [Priority] = 'Low' then [Value] end)

PostGIS - Count Points in Polygons (and average their features within the boundaries)

I've a table with some points representing buildings :
CREATE TABLE buildings(
pk serial NOT NULL,
geom geometry(Point,4326),
height double precision,
area double precision,
perimeter double precision
)
And another table with polylines(most of them closed):
CREATE TABLE regions
(
pk serial NOT NULL,
geom geometry(Polygon,4326)
)
I would like to:
count the numbers of points inside each regions (buildings_n)
find the average value of one the features(eg. area) within the regions boundary (area_avg)
Adding the two new columns:
ALTER TABLE regions ADD COLUMN buildings_n integer;
ALTER TABLE regions ADD COLUMN area_avg double precision;
How can I do these two queries?
I've tried this one for the point 1, but it fails:
INSERT INTO regions (buildings_n)
SELECT count(b.geom)
FROM regions a, buildings b
WHERE st_contains(a.geom,b.geom);
thank you,
Stefano
Region geometry
The first problem you have is that ST_Contains with 'polylines' or linestrings only finds the points that are exactly on the linestring's geometry. If you want points within a region represented by a linestring it won't work, especially if these are not closed. See the examples of valid ST_Contains relations here:
http://www.postgis.org/docs/ST_Contains.html
For the spatial relation to work you have to transform the region's geometry to polygons, either beforehand or on the fly in the query. For example:
ST_Contains(ST_MakePolygon(a.geom),b.geom)
See this reference for more info:
http://www.postgis.org/docs/ST_MakePolygon.html
Calculate aggregate values
The second problem is that to use the aggregate functions count or average on subsets of the buildings table (and not the entire table) you need to associate the region id with each building...
SELECT a.pk region_pk, b.pk building_pk, b.area
FROM regions a, buildings b
WHERE ST_Contains(ST_MakePolygon(a.geom),b.geom)
.. and then group your building data by the region they belong to:
SELECT region_pk, count(), avg(area) average
FROM joined_regions_and_buildings
GROUP BY region_pk;
Update new columns
The third problem is that you are using INSERT to add values to the newly created columns. INSERT is for adding new records to a table, UPDATE is used for changing values of existing records in a table.
Solution
So, all of the points above combined result in the following query:
WITH joined_regions_and_buildings AS (
SELECT a.pk region_pk, b.pk building_pk, b.area
FROM regions a, buildings b
WHERE ST_Contains(ST_MakePolygon(a.geom),b.geom)
)
UPDATE regions a
SET buildings_n = b.count, area_avg = b.average
FROM (
SELECT region_pk, count(), avg(area) average
FROM joined_regions_and_buildings
GROUP BY region_pk
) b
WHERE a.pk = b.region_pk;