SQL Server - how to pass variable to nested query?
Asked By lightw
26-Oct-07 07:30 PM
how to assign the @title global so the inner query, the 2nd select, will know
what it is? thanks.
declare @title nvarchar(100);
set @title='testing';
select *
from a
where id=@title
and (select * from b where id=@title);
SQL Server
(1)
Virtual PC
(1)
Nvarchar
(1)
Declare
(1)
Inner
(1)
PhD
(1)
BSc
(1)
Toronto
(1)
Tom Moreau replied...
That will work. What problem are you experiencing?
--
Tom
----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
SQL Server MVP
Toronto, ON Canada
https://mvp.support.microsoft.com/profile/Tom.Moreau
how to assign the @title global so the inner query, the 2nd select, will
know
what it is? thanks.
declare @title nvarchar(100);
set @title='testing';
select *
from a
where id=@title
and (select * from b where id=@title);
Sylvain Lafontaine replied...
Without making any offense, you should explain what you are trying to do
with your query; ie., what's the result that you want to get from your
tables A and B.
--
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail: sylvain aei ca (fill the blanks, no spam please)
Mansi Shah replied...
Hi,
You have not specified which kind of problem you are facing, but then
also As per my knowledge this will not work properly. I think you are
trying the fetch records from both tables. I will suggest you to use
query like,
--------
declare @title nvarchar(100);
set @title='testing';
select a.id,a.title,a.name,b.id,b.title,b.name from a inner join b on
a.id=b.id where id=@title
--------
You can use as many fields you like by 'table name.field name'.
Regards,
Mansi Shah.
*** Sent via Developersdex http://www.developersdex.com ***
MSDE on Windows 2003 R2 box, new DL385G6 - Install Fails during SQL Services SQL Server I have been finding that I am having trouble with the Crystal Reports Server XI installation failing when it is dealing with SQL. So, as a thought and in case there was something wrong with my SQL portion of the isntall. I thought ok, I will try installing the actual MSDE application direct from Microsoft. So, I downloaded the MSDE for SQL 2000 (which is msde2000a.exe), set my switches and off to the races. It quit seconds left to the installation and bombed with the same errors as the Crystal Reports Server install. The error is the same whether I try to install MSDE by itself or
Why_can’t_recursive_queries_contain. . .? SQL Server hi I hope I didn = 92t put too many questions 1) Why can = 92t recursive queries also be unioned together with UNION operator ( instead they must use UNION ALL )? thanx SQL Server Programming Discussions SQL Server 2008 (1) SQL Server 2005 (1) SQL Server 2000 (1) SQL Server (1) Oracle (1) Ruby (1) MichaelcoAToptonlineDOTnet (1
KB948110 / MS08-040, SQL 2000 & sa authentication SQL Server Hi everyone, I'm having an issue installing KB948110 / MS08-04 security patch for SQL Server 2000 Standard. I'm getting the message: 1 or more SQL Server instances could not verify your account information when I provide sql authentication details when installing this patch. We have installed SQL Server 2000 STD on a
SQL Express: Failed Reinstall SQL Server Dear Setup Experts: I am trying to reinstall SQL Express after playing with it some. I uninstalled it, and now, it refuses to reinstall in the face. Any ideas what this log file means and how I can get SQL Express installed? I really do not want to have to reinstall my whole system. * ** ** Start of Log File Overall summary: Final result: SQL Server installation failed. To continue, investigate the reason for the failure, correct the problem, uninstall SQL Server, and then rerun SQL Server Setup. Exit code (Decimal): -2068643839 Exit facility code: 1203
Update is not working without Go in sp SQL Server Hello Everybody, I have sp where I’m creating a table then inserting data there it’s creating a problem that declared variables are not visible and I need to declare it locally inside GO batch and most importantly the one output variable I’m declaring anybody explain why my sp is not updating a table without adding GO there? Thanks SQL Server Programming Discussions USAYCategory.SurveyID (1) USAYCategory.PageID (1) SQL Server (1) Virtual PC (1) SurveyItem.surveyID (1) SurveyItem.itemID (1) SurveyItem.pageID (1) AllResponses.Responseid (1) You