Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

view with Stored procedure?

Status
Not open for further replies.

PapaSmurf

IS-IT--Management
May 16, 2001
48
GB
I have a table with the following fields; TranID, Date, Type, Account, Amount.

I pull a list of Accounts (Companies) with:

SELECT Distinct Account FROM Table

I've also got a Stored procedure:

CREATE PROCEDURE Procedure
@supplier varchar(3),
@type varchar(2),
@datefrom varchar(8),
@dateto varchar(8)
AS
(Select sum(Amount) from Table WHERE Account=@supplier and Type=@type and Date>=@datefrom and Date<=@dateto)
GO

Which gives me a sum of Invoices for a particular Account, with a certain date range.

What I'm after is a stored proc that will return a table of account and sum. Can anyone point me in the right direction?

Thanks

Ben

 
if you are using SQL Svr 2000 then you can use a function to return a table

Code:
CREATE FUNCTION SalesByStore (@storeid varchar(30))
RETURNS TABLE
AS
RETURN (SELECT title, qty
      FROM sales s, titles t
      WHERE s.stor_id = @storeid and
      t.title_id = s.title_id)

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top