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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Stored Proc that has output values

Author  Topic 

FrankC
Starting Member

2 Posts

Posted - 2009-07-08 : 13:07:24
Hello, I am new to TSQL.
I need to create a stored proc that will return records. I would like to return back AccountID, FirstName, LastName & email.

For example, I am comparing two tables using the AccountID fields.
So currently my query is:

Select AccountID, FirstName, LastName, email
from tblCustomers
Where AccountID not in
(select AccountID from tblVendors)

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-07-08 : 13:12:32
what will you be passing as input to sp? Account ID? if yes, it would be like



CREATE PROC GetData
@AccountID int
AS
BEGIN
Select AccountID, FirstName, LastName, email
from tblCustomers
Where AccountID =@AccountID
END
GO
Go to Top of Page

FrankC
Starting Member

2 Posts

Posted - 2009-07-08 : 13:15:07
not passing anything. This is just comparing two tables, so I dont think I need to pass anything
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-07-08 : 13:30:18
then this is enough

CREATE PROC GetData
AS
BEGIN
Select AccountID, FirstName, LastName, email
from tblCustomers
Where AccountID not in
(select AccountID from tblVendors)
END
GO


you can also use NOT EXISTS or LEFT JOIN instead of NOT IN
Go to Top of Page
   

- Advertisement -