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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 select query procedure

Author  Topic 

soorajtnpki
Posting Yak Master

231 Posts

Posted - 2008-11-12 : 00:40:10
hi experts,
i want to build a procedure that bring data from different tables like below

CREATE PROCEDURE [dbo].usp_name
(
declarations
)
AS
BEGIN
set no count on
select data1 from table1 where conditions
end
BEGIN
set no count on
select data1,data6 from table2 where conditions
end
BEGIN
set no count on
select data1,data7 from table3 where conditions
end
BEGIN
set no count on
select data1 from table4 where conditions
end

is it necessary to put begin end for each select queries..
or can i club them in a single begin end

malaytech2008
Yak Posting Veteran

95 Posts

Posted - 2008-11-12 : 00:44:48
This is sufficient..

CREATE PROCEDURE [dbo].usp_name
(
declarations
)
AS
BEGIN
set no count on
select data1 from table1 where conditions

select data1,data6 from table2 where conditions

select data1,data7 from table3 where conditions

select data1 from table4 where conditions
end



malay
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-12 : 00:47:11
unless you've some IF ELSE condition checks for each selects you need only a single begin end. But just in case what you're trying is to return different result sets for different conditions you need seperate BEGIN ENDs...
Go to Top of Page

malaytech2008
Yak Posting Veteran

95 Posts

Posted - 2008-11-12 : 01:01:16
thats right.only for block condition. we need BEGIN and END

malay
Go to Top of Page

soorajtnpki
Posting Yak Master

231 Posts

Posted - 2008-11-12 : 01:03:05
i want all select queries to return data at all times..ie all queries should return at all times
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-12 : 01:04:38
quote:
Originally posted by soorajtnpki

i want all select queries to return data at all times..ie all queries should return at all times


then what malay posted is sufficient
Go to Top of Page
   

- Advertisement -