Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 3rd, 2007, 02:11 AM
Registered User
 
Join Date: Oct 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Query Parameter of a Stored Procedure

I would like to write a query that would return both the names and types of paramters for a given stored procedure. In another words if there was a stored procedure call "MyStoredProcedure" and it took two parameters, @P1 of type int, and @P2 of nvarchar(25), then the query SELECT ?????? WHERE ????? = 'MyStoredProcedure' would return @RETURN_VALUE int, @P1 int, @P2 nvarchar(25); or at least something close to that.

I would also like to do the same thing for a table; given a table name enumerate the fields and their types.

 
Old July 9th, 2007, 10:50 PM
SQLScott's Avatar
Wrox Author
 
Join Date: Dec 2004
Posts: 338
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Hi Tarang,

You can't have Input and Output parameters with teh same name. Meaning, you can't do the following:

CREATE PROCEDURE MyStoredProcedure
    @P1 int,
    @P2 nvarchar(25),
    @P1 int OUPUT,
    @P2 nvarchar(25) OUPUT
AS
   blah blah


What is your reasoning behind trying to use the same parameter names for input and output?

Scott Klein
Author - Professional SQL Server 2005 XML
http://www.wrox.com/WileyCDA/WroxTit...764597922.html
 
Old July 14th, 2007, 06:37 PM
Registered User
 
Join Date: Oct 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

SQLScott I think you missunderstood what I wanted. Here's what I ended up with:

ALTER PROCEDURE [dbo].[spGetSPParameters]
    @sSPName nvarchar(255)
AS
BEGIN
    SET NOCOUNT ON

    SELECT
        sysCol.NAME AS [sParameterName],
        sysTy.NAME AS [sParameterType],
        sysCol.LENGTH AS [iParameterLength]
    FROM
        sysobjects sysObj
        INNER JOIN syscolumns sysCol ON sysObj.id = sysCol.id
        INNER JOIN systypes sysTy ON sysCol.xtype = sysTy.xtype
    WHERE
        sysObj.name = @sSPName and
        sysTy.name <> 'sysname'
    ORDER BY
        sysCol.colid

END
GO

 
Old July 16th, 2007, 03:04 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

I think you need to revisit your joins posted here. I dont think it would give correct output when there are multiple entries with same name in the database. (say a column that exists with same name in multiple tables with different datatypes/length)

_________________________
- Vijay G
Strive for Perfection
 
Old July 25th, 2007, 11:43 AM
Registered User
 
Join Date: Oct 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Although it's true that the joins will return more than I might want I think that the WHERE clause should narrow it down to exactly what I want.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Pass XML parameter to stored procedure BCullenward Classic ASP Databases 3 September 10th, 2008 02:07 PM
usin g stored procedure with parameter Sheraz Khan ASP.NET 2.0 Basics 1 September 5th, 2007 12:27 AM
How to pass a parameter to a stored procedure? MaxGay2 VB.NET 2002/2003 Basics 1 November 8th, 2006 02:48 PM
Passing a parameter value to Stored Procedure mcinar SQL Server 2000 9 October 3rd, 2004 09:42 PM
passing table as a parameter to stored procedure pankaj_daga SQL Server 2000 7 September 30th, 2003 05:11 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.