473,394 Members | 1,916 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Getting Result of query inside another query


Hi to all,

I just need to get two fields from a table and manipulate the results
in next query of a procedure.I planned to code like what you see
below,

create procedure marks1
as
@ sql1 as varchar(50)

@ sql1=select registerno ,subjectcode from mark;

begin

select * from marksetting where re**********@sql1.registerno' and
su***********@sql1.subjectcode';

end
can it be possible to get the results as shown in the code? else
propose an alternative for this scenario.

Thanks in Advance.

May 22 '07 #1
4 8668
I just need to get two fields from a table and manipulate the results
in next query of a procedure.I planned to code like what you see
below,
Why not use a single query? For example:

CREATE PROCEDURE dbo.marks1
AS

SELECT *
FROM dbo.marksetting
JOIN dbo.mark ON
mark.registerno = marksetting.registerno AND
mark.subjectcode = marksetting.subjectcode;
GO
To answer your question, if the first query returns no more than a single
row, you could assign the result values to variables for use in the second
query:

CREATE PROCEDURE dbo.marks1
AS

DECLARE
@registerno int,
@subjectcode int

SELECT
@registerno = registerno,
@subjectcode = subjectcode
FROM dbp.mark;

SELECT *
FROM dbo.marksetting
WHERE
registerno = @registerno AND
subjectcode = @subjectcode;
GO
If the first query might return more than one row, you could store the
result in a temp table or variable for use in the second query:

CREATE PROCEDURE dbo.marks1
AS

DECLARE @results TABLE
(
registerno int,
subjectcode int
);

INSERT INTO @results
SELECT
registerno,
subjectcode
FROM dbo.mark;

SELECT *
FROM dbo.marksetting
JOIN @results AS r ON
marksetting.registerno = r.registerno AND
marksetting.subjectcode = r,subjectcode;
GO

--
Hope this helps.

Dan Guzman
SQL Server MVP

"meendar" <as****************@gmail.comwrote in message
news:11**********************@b40g2000prd.googlegr oups.com...
>
Hi to all,

I just need to get two fields from a table and manipulate the results
in next query of a procedure.I planned to code like what you see
below,

create procedure marks1
as
@ sql1 as varchar(50)

@ sql1=select registerno ,subjectcode from mark;

begin

select * from marksetting where re**********@sql1.registerno' and
su***********@sql1.subjectcode';

end
can it be possible to get the results as shown in the code? else
propose an alternative for this scenario.

Thanks in Advance.
May 22 '07 #2
On May 22, 3:33 pm, "Dan Guzman" <guzma...@nospam-
online.sbcglobal.netwrote:
I just need to get two fields from a table and manipulate the results
in next query of a procedure.I planned to code like what you see
below,

Why not use a single query? For example:

CREATE PROCEDURE dbo.marks1
AS

SELECT *
FROM dbo.marksetting
JOIN dbo.mark ON
mark.registerno = marksetting.registerno AND
mark.subjectcode = marksetting.subjectcode;
GO

To answer your question, if the first query returns no more than a single
row, you could assign the result values to variables for use in the second
query:

CREATE PROCEDURE dbo.marks1
AS

DECLARE
@registerno int,
@subjectcode int

SELECT
@registerno = registerno,
@subjectcode = subjectcode
FROM dbp.mark;

SELECT *
FROM dbo.marksetting
WHERE
registerno = @registerno AND
subjectcode = @subjectcode;
GO

If the first query might return more than one row, you could store the
result in a temp table or variable for use in the second query:

CREATE PROCEDURE dbo.marks1
AS

DECLARE @results TABLE
(
registerno int,
subjectcode int
);

INSERT INTO @results
SELECT
registerno,
subjectcode
FROM dbo.mark;

SELECT *
FROM dbo.marksetting
JOIN @results AS r ON
marksetting.registerno = r.registerno AND
marksetting.subjectcode = r,subjectcode;
GO

--
Hope this helps.

Dan Guzman
SQL Server MVP

"meendar" <askjavaprogramm...@gmail.comwrote in message

news:11**********************@b40g2000prd.googlegr oups.com...


Hi to all,
I just need to get two fields from a table and manipulate the results
in next query of a procedure.I planned to code like what you see
below,
create procedure marks1
as
@ sql1 as varchar(50)
@ sql1=select registerno ,subjectcode from mark;
begin
select * from marksetting where registern...@sql1.registerno' and
subjectcod...@sql1.subjectcode';
end
can it be possible to get the results as shown in the code? else
propose an alternative for this scenario.
Thanks in Advance.- Hide quoted text -

- Show quoted text -
Thanks Dan!

Indeed it was very helpful to me.

May 22 '07 #3
On May 22, 3:33 pm, "Dan Guzman" <guzma...@nospam-
online.sbcglobal.netwrote:
I just need to get two fields from a table and manipulate the results
in next query of a procedure.I planned to code like what you see
below,

Why not use a single query? For example:

CREATE PROCEDURE dbo.marks1
AS

SELECT *
FROM dbo.marksetting
JOIN dbo.mark ON
mark.registerno = marksetting.registerno AND
mark.subjectcode = marksetting.subjectcode;
GO

To answer your question, if the first query returns no more than a single
row, you could assign the result values to variables for use in the second
query:

CREATE PROCEDURE dbo.marks1
AS

DECLARE
@registerno int,
@subjectcode int

SELECT
@registerno = registerno,
@subjectcode = subjectcode
FROM dbp.mark;

SELECT *
FROM dbo.marksetting
WHERE
registerno = @registerno AND
subjectcode = @subjectcode;
GO

If the first query might return more than one row, you could store the
result in a temp table or variable for use in the second query:

CREATE PROCEDURE dbo.marks1
AS

DECLARE @results TABLE
(
registerno int,
subjectcode int
);

INSERT INTO @results
SELECT
registerno,
subjectcode
FROM dbo.mark;

SELECT *
FROM dbo.marksetting
JOIN @results AS r ON
marksetting.registerno = r.registerno AND
marksetting.subjectcode = r,subjectcode;
GO

--
Hope this helps.

Dan Guzman
SQL Server MVP

"meendar" <askjavaprogramm...@gmail.comwrote in message

news:11**********************@b40g2000prd.googlegr oups.com...


Hi to all,
I just need to get two fields from a table and manipulate the results
in next query of a procedure.I planned to code like what you see
below,
create procedure marks1
as
@ sql1 as varchar(50)
@ sql1=select registerno ,subjectcode from mark;
begin
select * from marksetting where registern...@sql1.registerno' and
subjectcod...@sql1.subjectcode';
end
can it be possible to get the results as shown in the code? else
propose an alternative for this scenario.
Thanks in Advance.- Hide quoted text -

- Show quoted text -
Thanks Dan!

Indeed it was very helpful to me.

May 22 '07 #4
I'm glad I was able to help.

--
Dan Guzman
SQL Server MVP

"meendar" <as****************@gmail.comwrote in message
news:11**********************@b40g2000prd.googlegr oups.com...
On May 22, 3:33 pm, "Dan Guzman" <guzma...@nospam-
online.sbcglobal.netwrote:
I just need to get two fields from a table and manipulate the results
in next query of a procedure.I planned to code like what you see
below,

Why not use a single query? For example:

CREATE PROCEDURE dbo.marks1
AS

SELECT *
FROM dbo.marksetting
JOIN dbo.mark ON
mark.registerno = marksetting.registerno AND
mark.subjectcode = marksetting.subjectcode;
GO

To answer your question, if the first query returns no more than a single
row, you could assign the result values to variables for use in the
second
query:

CREATE PROCEDURE dbo.marks1
AS

DECLARE
@registerno int,
@subjectcode int

SELECT
@registerno = registerno,
@subjectcode = subjectcode
FROM dbp.mark;

SELECT *
FROM dbo.marksetting
WHERE
registerno = @registerno AND
subjectcode = @subjectcode;
GO

If the first query might return more than one row, you could store the
result in a temp table or variable for use in the second query:

CREATE PROCEDURE dbo.marks1
AS

DECLARE @results TABLE
(
registerno int,
subjectcode int
);

INSERT INTO @results
SELECT
registerno,
subjectcode
FROM dbo.mark;

SELECT *
FROM dbo.marksetting
JOIN @results AS r ON
marksetting.registerno = r.registerno AND
marksetting.subjectcode = r,subjectcode;
GO

--
Hope this helps.

Dan Guzman
SQL Server MVP

"meendar" <askjavaprogramm...@gmail.comwrote in message

news:11**********************@b40g2000prd.googleg roups.com...


Hi to all,
I just need to get two fields from a table and manipulate the results
in next query of a procedure.I planned to code like what you see
below,
create procedure marks1
as
@ sql1 as varchar(50)
@ sql1=select registerno ,subjectcode from mark;
begin
select * from marksetting where registern...@sql1.registerno' and
subjectcod...@sql1.subjectcode';
end
can it be possible to get the results as shown in the code? else
propose an alternative for this scenario.
Thanks in Advance.- Hide quoted text -

- Show quoted text -

Thanks Dan!

Indeed it was very helpful to me.
May 23 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Wm | last post by:
I'm totally clueless on this one -- I'm getting 3 copies of every Email (in plain text, not HTML as expected), from a single mail() line... Can anyone tell me what might be causing the duplicates??...
3
by: James | last post by:
Please help - getting very desperate! Sun, 12 October 2003 05:39 I have PHPDEV 4.2.3 from Firepages.com.au as the upgrade to 4.3.0 did not work. I also had an abortive download from PHP.NET as...
13
by: dogu | last post by:
Noob alert. Code is below. File is saved as a .php. What I'm trying to do: User uses 'select' box drop down list to pick a value. Value ($site) is derived from a db query. This works fine....
4
by: s99999999s2003 | last post by:
hi the database "execute" function returns a list of logical results. Each logical result is a list of row tuples, as explained in the documents. everytime i use it to execute various...
9
by: Petr Vileta | last post by:
Hi, I'm new here and excuse me if this question was be here earlier. I have a simple code <html><body> <?php <?php $link = mysql_connect("localhost", "user", "password") or die("Grr: " ....
9
by: phopman | last post by:
Hello! I am currently working on a project. And have been assigned to get up to speed quickly on php. And even though I love the language, it's not easy to get up to speed in like 2 seconds :-) ...
1
by: raghuvendra | last post by:
Hi I have a jsp page with 4 columns: namely Category name , Category order, Input field and a submit button. All these are aligned in a row. And Each Category Name has its corresponding Category...
4
by: jeddiki | last post by:
Hi, I am using a dynamic redirect to take vistors to the database stored url as in this part of the script: $sql = "SELECT ad_link FROM adverts WHERE advert_id = $N_ad_id"; $result...
45
by: angelicdevil | last post by:
i have 2 tables 1 is status_type with field name status and other is users with field username and status now i want that the first listbox lists all status from status type ( this i have achieved...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.