EDIT:
Example in question might not be ideal for what I want,cause it always gives one result. Basically, I want a way to select all columns from one table plus a calculated value (Country in my case) where the id passed to that stored procedure is the itm.ID (Resulting in many rows)
Veera gave a working solution, I wonder if this can be done more efficiently with a stored procedure.
I'm a beginner using SQL Server, and I hope to get help with the following: I'm writing a stored procedure that calls another stored procedure.
The main stored procedure looks like this:
ALTER PROCEDURE [Store].[usp_GetItem]
(
@ID INT ,
@Name NVARCHAR(255),
@GroupNum INT
)
AS
BEGIN
SET NOCOUNT ON
SELECT *
FROM Items itm
WHERE itm.ID = @ID
AND itm.Name = @Name
AND itm.GroupNum = @GroupNum
END
Now, I have another stored procedure that looks like this:
ALTER PROCEDURE Country
(@ID INT)
AS
BEGIN
SET NOCOUNT ON
DECLARE @CountryName NVARCHAR(255)
Set @CountryName = SELECT Name
FROM General_c_Country
WHERE ItemID = @ID
SELECT @CountryName
END
Now, I want the first procedure to pass the ID of the item (itm.ID) to the second procedure,
get the result (the country name) and then the main stored procedure to display records of:
ID Name GroupNum Country
-------------------------------------------------------------
1 Page 32 Spain (Country of Item with ID1
and so on...
Note: I know this can be simply done within one procedure with a simple inner join. Yet, I want to know how to do this in the way I have described. Thanks!