Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Report from multiple tables. Expand / Collapse
Author
Message
Posted Thursday, May 9, 2013 9:35 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, June 12, 2014 9:26 AM
Points: 22, Visits: 112
I need to create a report. I have data in one table that represents street ranges. Example.
from to street category
100 200 Adams CFMH
300 400 Smith CFHM

There are numeroous ranges in the table above but I need to use the category code CFMH

I then have a second table that has historical information that referenced these ranges.
Example
streetno street
123 Adams
245 Adams
333 Smith

I need to pull the historical data based on the ranges.

Thanks,
Bill
Post #1451201
Posted Thursday, May 9, 2013 10:16 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Wednesday, November 6, 2013 10:15 AM
Points: 54, Visits: 96

Your post is not clear in terms of the column names and what exactly are you looking at. Do you need a parameter in this report?

You should just be able to write a simple query for this as a dataset, joining both the tables based on the common column from both the table.

From example: You probably need two different datasets
Main dataset for report
SELECT A.*

FROM HistoricalTable as A
, RangeTable as B

WHERE A.CommonColumn = B.CommonColumn
AND B.StreetCategory LIKE '%CFHM'
AND B.StreetCategory = @StreetRanges;

Secondary dataset for parameter StreetRanges

Select DISTINCT StreetCategory

FROM RangeTable;


Now once you create your report, CLICK on the parameter @StreetRanges, SELECT "AvailableValues" -> then "Get values from a query". Choose the second dataset and the field that you've created to get the list of all the distinct ranges.

Hope this helps

Post #1451249
Posted Thursday, May 9, 2013 11:45 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, June 12, 2014 9:26 AM
Points: 22, Visits: 112
Well I apologize as I am not very good at explaining this. We have a computer aided dispatch system with a sql database that stores information about 911 calls. Such as address, caller, time the call time came in, time units dispatched, arrived and so on.
We have quite a lot of apartment buildings and we are trying find a way to run reports on those apartments. In the table where call information is stored there is a street number field and a street name field. There is also another table that stores information about street ranges. There is from street#, a to street# and the street name. There is also a category field. What we planned on doing is getting the from street, to street and street name from this table based on a certain category. Then using this information get the information from the other table from the street# and street name columns.
I have tried subqueries and derived columns to get the data and I don't think a join will work in this case.

Here is kind of what I think I need to do.
Query:select rangefr, rangeto, street from premrang where category = 'CFMH'
Results.
3900 3900 N FULTON AVE
600 600 RESERVE BLVD
700 700 RESERVE BLVD
400 499 APPLEWOOD CT
4400 4699 APPLEWOOD CT

Take that information and loop it through this query.

select * from inmain
where calltime > '2013-01-01'
and streetno > 400
and streetno < 499
and streetonly = 'APPLEWOOD CT'

I am think I should be able to get the data I want but I have not put it together yet.

Post #1451281
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse