Click here to Skip to main content
15,907,874 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
In the following Stored Procedure I want to select just all fields of the Med table and I want not to separate its field names, I want to use the Stored Procedure like this without selecting the fields of non required tables. Is there a way to do that?

Thanks.
USE [pharm lastver]
GO
/****** Object:  StoredProcedure [dbo].[SP_Med_SelectAllMed_ByActiveID]    Script Date: 05/14/2011 22:22:59 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
craete proc [dbo].[SP_Med_SelectAllMed_ByActiveID]
@P_Activemat_ID int
as
begin
select * from Med,Active_material,Active_mat_med
where Med.Med_ID=Active_mat_med.Med_ID
and Active_material.Activemat_ID=Active_mat_med.Activemat_ID
and Active_material.Activemat_ID=@P_Activemat_ID
end
Posted
Updated 15-May-11 10:51am
v2
Comments
Fabio V Silva 15-May-11 16:51pm    
Edited formatting.

You need to explicitly select the columns. Say you had the fields id, name and active in the table Med, the start of your query becomes:
SQL
select id, name, active from
It is generally good practice to do this as you pick the fields that you want to retrieve and don't retrieve the ones you want. There's normally one or two fields you don't want returning, and selecting them is wasteful of resources.
 
Share this answer
 
hello,

If you want to select all the column in the med table, just replace * with Med.* or you can use Med.column1, Med.column2, Med.column3, etc...

SQL
select med.* from Med,Active_material,Active_mat_med
where Med.Med_ID=Active_mat_med.Med_ID
and Active_material.Activemat_ID=Active_mat_med.Activemat_ID
and Active_material.Activemat_ID=@P_Activemat_ID
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900