Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
yogi86
Starting Member
13 Posts |
Posted - 2011-06-23 : 16:46:14
|
Hello all,I have a tough question that I hope can be fully explained and easily understood through text with little/no visual help.Problem:I have 5 queries that I run in a sequential order to get 5 different answers. Query #1 uses a 'Identifying Code' to pull an 'Operating Number' and 'Phone Number'Query #2 uses the 'Operating Number' from #1 to find an 'Operating Name'Query #3 uses 'Identifying Code' to pull 'Server_Name'Etc Etc....But my problem (and reason I dont use 'Inner Join/Where' is that Query 2-5 use a single result from Query 1. Any help would be greatly appreciated. I understand im being very vague with this question. Here is a post of my multi-stepped query:--1.)selectfrom dbo.DATA (nolock)where place like ('Texas') and BLOCK_ID='A'order by place--2.) select *from dbo.DATA_NAMEwhere call_number in ('1234')--3.) --a.select *from dbo.DATA_CallNAmewhere place in ('Texas')--b. select *from citywhere city = 'Dallas'and Status = 'Active'--4.) select* from phone_listwhere phone_first='906' and phone_last='676'It is important to note that phone_first, phone_last, city, and call_number are generated by #1. Is it possible to have the remaining queries auto-populate with these answers?? |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
jfarrugia
Yak Posting Veteran
55 Posts |
Posted - 2011-06-24 : 06:19:19
|
something like:IF #1 returns ONLY one resultdeclare all variables...select @phone_first = phone_first, @phone_last = phone_last, @place = place, @call_number = call_numberfrom dbo.DATA (nolock)where place like ('Texas') and BLOCK_ID='A'order by placeIF #2 could possible return more than one resultINSERT all results from #1 into a temp tablefollowing.. in #2 - #5.. WHERE xxxx IN () etc.. should workWhere software development knowledge meets the reader |
|
|
yogi86
Starting Member
13 Posts |
Posted - 2011-06-24 : 10:15:23
|
Thank you very much tkizer and jfarrugia! |
|
|
|
|
|