May 13, 2013 at 11:23 am
Well I tried this in the reporting services forum got 1 reply and it seems to have fallen into the crack. I have not presented my request here the same as I did in the forum.
Anyway, I am trying to write a report. The primary query looks like this.
Select
*
from streets
where
calltime >= 'Sometime'
and
street = 'Some street' (streetname)
and
streetnumber >= somenumber (streetfrom)
and
streetnumber <= somenumber (streetto)
The values for the where clause will come form this query and I need to loop these values through the first query.
select
streetname,streetfrom,streetto
from streetranges
where
streetcategory = 'CFMH'
May 13, 2013 at 12:15 pm
The reason you did not get any responses in your original thread (http://www.sqlservercentral.com/Forums/Topic1451201-150-1.aspx) will be the same reason you don't get any here. You didn't post enough information for anybody to help.
We can't see your screen, we don't your business requirements, we are not intimate with your data structures and we have no concrete idea of what you are trying to do.
I have a feeling the sql for this is pretty easy but without details we are shooting in the dark.
Please take a few minutes and read the first article in my signature for best practices when posting questions. Then come back and post ddl, sample data and desired output. You will find lots of people willing and able to help joining in very quickly.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
May 13, 2013 at 12:59 pm
I work at a 911 center. Our data is sensitive and proprietary. I also have a contract with our software vendor to not disclose any information about their software. With that in mind this is why I posted the way I did, most of the names I used are not even used in the actual database. I tried to explain what I need without getting into to much detail about the data and I thougt what I sent might be enouigh.
I will try again.
May 13, 2013 at 1:46 pm
William Gary Wright (5/13/2013)
I work at a 911 center. Our data is sensitive and proprietary. I also have a contract with our software vendor to not disclose any information about their software. With that in mind this is why I posted the way I did, most of the names I used are not even used in the actual database. I tried to explain what I need without getting into to much detail about the data and I thougt what I sent might be enouigh.I will try again.
I certainly understand sensitive data. Many of us around here work with sensitive data as a normal part of our day. For these types of things you just need obfuscate the data but keep it representative of the issue. Certainly nothing wrong with changing column names and only including columns relevant to the issue at hand. That makes it an example of how to do whatever it is you are doing and does reveal any real actual information.
I was pretty sure that all you needed was to join those two tables until I ran into this:
The values for the where clause will come form this query and I need to loop these values through the first query.
select
I have no idea what that means.
I was thinking initially that you wanted something like you were trying to use streetranges columns as some way to validate what is there.
Completely blind due to no information but here are a couple of shots in the dark.
Select
*
from streets s
join streetranges sr on sr.streetnumber = s.streetnumber
join streetranges sr2 on sr.streetname = s.streetname
OR MAYBE...
select *
from streets s
where
calltime >= 'Sometime'
and
street in (select streetname from streetranges)
and
streetnumber >= (select min(streetfrom) from streetranges)
and
streetnumber <= (select min(streetto) from streetranges)
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
May 13, 2013 at 3:24 pm
Does this give you what you are looking for?
Select
*
from
streets s
inner join streetranges sr
on (s.street = sr.streetname and
s.streetnumber >= sr.streetfrom and
s.streetnumber <= s.streetto)
where
calltime >= 'Sometime' and
sr.streetcategory = 'CFMH';
May 14, 2013 at 1:22 am
If streetranges is actually the result of the first query, you could try a CTE (common table expression - look it up in Books Online) to create and then use it . Or a temp table if you're on an earlier version of sql server.
May 14, 2013 at 7:00 am
I left the office last night being half way done writing a script to create a database with some data in it for you all to look at. I came in this morning and read the new replies to my post. I had never considered a join. All of the examples of joins I have seen there was always an = involved and I had not seen >= used in a join. This worked great and it makes sense to me.
Thanks Lynn,
Bill
PS
How does this points thing work?
May 14, 2013 at 7:12 am
William Gary Wright (5/14/2013)
I left the office last night being half way done writing a script to create a database with some data in it for you all to look at. I came in this morning and read the new replies to my post. I had never considered a join. All of the examples of joins I have seen there was always an = involved and I had not seen >= used in a join. This worked great and it makes sense to me.Thanks Lynn,
Bill
PS
How does this points thing work?
How you view the points is up to you actually. Some view it as a show of experience on the site, of a supposed level of knowledge. Others just view it as a level of activity in this particular community.
May 14, 2013 at 7:13 am
William Gary Wright (5/14/2013)
I left the office last night being half way done writing a script to create a database with some data in it for you all to look at. I came in this morning and read the new replies to my post. I had never considered a join. All of the examples of joins I have seen there was always an = involved and I had not seen >= used in a join. This worked great and it makes sense to me.Thanks Lynn,
Bill
PS
How does this points thing work?
This article is worth to read (about hidden "RBAR" in triangular joins):
May 14, 2013 at 7:16 am
Eugene Elutin (5/14/2013)
William Gary Wright (5/14/2013)
I left the office last night being half way done writing a script to create a database with some data in it for you all to look at. I came in this morning and read the new replies to my post. I had never considered a join. All of the examples of joins I have seen there was always an = involved and I had not seen >= used in a join. This worked great and it makes sense to me.Thanks Lynn,
Bill
PS
How does this points thing work?
This article is worth to read (about hidden "RBAR" in triangular joins):
Eugene,
Yes, it is a good article on triangular joins, I just hope you don't think that the code I provided is a triangular join. It is actually a bound join with a lower an upper bound.
May 14, 2013 at 8:22 am
Lynn Pettis (5/14/2013)
Eugene Elutin (5/14/2013)
William Gary Wright (5/14/2013)
I left the office last night being half way done writing a script to create a database with some data in it for you all to look at. I came in this morning and read the new replies to my post. I had never considered a join. All of the examples of joins I have seen there was always an = involved and I had not seen >= used in a join. This worked great and it makes sense to me.Thanks Lynn,
Bill
PS
How does this points thing work?
This article is worth to read (about hidden "RBAR" in triangular joins):
Eugene,
Yes, it is a good article on triangular joins, I just hope you don't think that the code I provided is a triangular join. It is actually a bound join with a lower an upper bound.
No, it has nothing to do with your code. Just OP has stated that he has never seen JOINs with "<=" used before. So, I thought, before OP will became to excited about it, he better to be aware of triangular join problem which may occur when "non-equal" compare is used in joins.
May 14, 2013 at 10:02 am
Eugene Elutin (5/14/2013)
Lynn Pettis (5/14/2013)
Eugene Elutin (5/14/2013)
William Gary Wright (5/14/2013)
I left the office last night being half way done writing a script to create a database with some data in it for you all to look at. I came in this morning and read the new replies to my post. I had never considered a join. All of the examples of joins I have seen there was always an = involved and I had not seen >= used in a join. This worked great and it makes sense to me.Thanks Lynn,
Bill
PS
How does this points thing work?
This article is worth to read (about hidden "RBAR" in triangular joins):
Eugene,
Yes, it is a good article on triangular joins, I just hope you don't think that the code I provided is a triangular join. It is actually a bound join with a lower an upper bound.
No, it has nothing to do with your code. Just OP has stated that he has never seen JOINs with "<=" used before. So, I thought, before OP will became to excited about it, he better to be aware of triangular join problem which may occur when "non-equal" compare is used in joins.
Okay, just wanted to be sure. Didn't want the article to scare off the OP from the code I provided.
Definitely a good thing to point out the issues that can occur with triangular joins.
Viewing 12 posts - 1 through 11 (of 11 total)
You must be logged in to reply to this topic. Login to reply