Results 1 to 3 of 3

Thread: M$SQL:Stored Procedures - Executing Procedure in a Procedure? [Resolved]

  1. #1

    Thread Starter
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622

    Resolved M$SQL:Stored Procedures - Executing Procedure in a Procedure? [Resolved]

    Can i shorten sp_ArtistFromLyricID by executing sp_AlbumFromLyricID?


    Code:
    CREATE PROCEDURE sp_ArtistFromLyricID
    (
    	@LyricID			bigint
    )
    AS
    BEGIN
    
    	SELECT
    		Data_Artists.*, Data_Albums.*, Data_Songs.*, Data_Lyrics.*
    	FROM
    		Data_Artists INNER JOIN Data_Albums
    			ON Data_Artists.ArtistID = Data_Albums.ArtistID
    		INNER JOIN Data_Songs
    			ON Data_Albums.AlbumID = Data_Songs.AlbumID
    		INNER JOIN Data_Lyrics
    			ON Data_Songs.SongID = Data_Lyrics.SongID
    	WHERE
    		Data_Lyrics.LyricID = @LyricID
    END
    GO
    Code:
    CREATE PROCEDURE sp_AlbumFromLyricID
    (
    	@LyricID			bigint
    )
    AS
    BEGIN
    
    	SELECT
    		Data_Albums.*, Data_Songs.*, Data_Lyrics.*
    	FROM
    		Data_Albums
    		INNER JOIN Data_Songs
    			ON Data_Albums.AlbumID = Data_Songs.AlbumID
    		INNER JOIN Data_Lyrics
    			ON Data_Songs.SongID = Data_Lyrics.SongID
    	WHERE
    		Data_Lyrics.LyricID = @LyricID
    END
    GO
    Last edited by <ABX; Nov 19th, 2004 at 10:59 AM.
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  2. #2
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263
    I'm not completely sure I understand your question - but yes you can EXEC {sprocname} from within another SPROC.

    We sometimes pass an @OPT parameter to a SPROC - and do something like:

    Code:
    IF @OPT=1
    Begin
         Select ...
         Return
    End
    
    IF @OPT=2
    Begin
         Exec SomeSprocName
         Return
    End
    It's much harder to EXEC a SPROC and get it's values joined into another query - usually have to create a TABLE VARIABLE to EXEC the results of the SPROC into and then JOIN to that.

    BTW - What's with all the * usage - that's generally frowned upon in production work. If you have a VB client APP that expects let's say 10 columns from some table and then next year you add an elevent column - you can have a nightmare fixing those * column ref's. We would not allow our programming staff to use * references to columns

  3. #3

    Thread Starter
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622
    The * was just for testing purposes.... i was too lazy to write out all the columns if it wasnt going to work...
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

Posting Permissions

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



Click Here to Expand Forum to Full Width