SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Query Impossible?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

yogi86
Starting Member

USA
13 Posts

Posted - 06/23/2011 :  16:46:14  Show Profile  Reply with Quote
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.)
select
from dbo.DATA (nolock)
where place like ('Texas') and BLOCK_ID='A'
order by place

--2.)
select *
from dbo.DATA_NAME
where call_number in ('1234')

--3.)
--a.
select *
from dbo.DATA_CallNAme
where place in ('Texas')

--b.
select *
from city
where city = 'Dallas'
and Status = 'Active'


--4.)
select*
from phone_list
where 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

USA
37466 Posts

Posted - 06/23/2011 :  16:53:29  Show Profile  Visit tkizer's Homepage  Reply with Quote
Using #1, put them all into variables and then use those variables for your further queries.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

jfarrugia
Yak Posting Veteran

55 Posts

Posted - 06/24/2011 :  06:19:19  Show Profile  Reply with Quote
something like:

IF #1 returns ONLY one result

declare all variables...

select @phone_first = phone_first, @phone_last = phone_last, @place = place, @call_number = call_number
from dbo.DATA (nolock)
where place like ('Texas') and BLOCK_ID='A'
order by place

IF #2 could possible return more than one result

INSERT all results from #1 into a temp table

following.. in #2 - #5.. WHERE xxxx IN () etc.. should work


Where software development knowledge meets the reader
Go to Top of Page

yogi86
Starting Member

USA
13 Posts

Posted - 06/24/2011 :  10:15:23  Show Profile  Reply with Quote
Thank you very much tkizer and jfarrugia!
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000