Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2004
    Posts
    134

    Unanswered: Call stored procedure within SELECT statement

    Can this be done? I want to call a stored procedure from inside a select statement. Since you can nest select statements, I thought it might be possible but I have no idea how to do it.

    Code:
    USE NORTHWIND 
    GO
    
    CREATE TABLE tbA (
    Item int NOT NULL,
    Value int NOT NULL
    ) ON [PRIMARY]
    
    GO
    
    INSERT INTO tbA (Item, Value)
    SELECT 1, 10 UNION ALL
    SELECT 2, 5 UNION ALL
    SELECT 3, 2 
    GO
    
    CREATE PROCEDURE usp_SquareIt
    
    @iItem int
    
    AS
    
    declare @iValue int
    SELECT @iValue = Value FROM tbA
    SELECT @iValue * @iValue AS Result
    
    GO
    
    SELECT Item,
    	EXECUTE usp_SquareIt Item AS Squared ---- can this be done
    FROM tbA
    GO
    
    DROP TABLE tbA
    GO
    
    DROP PROCEDURE usp_SquareIt
    GO
    Any thoughts?

    Mike B

  2. #2
    Join Date
    Aug 2002
    Location
    Scotland
    Posts
    1,578
    http://www.sqlteam.com/item.asp?ItemID=2644 for relevance of the topic.

    HTH
    --Satya SKJ
    Microsoft SQL Server MVP
    [IMG]http://sqlserver-qa.net/google_bart.gif[/IMG]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •