Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 3rd, 2007, 02:11 AM
Registered User
 
Join Date: Oct 2003
Location: , , .
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.

Reply With Quote
  #2 (permalink)  
Old July 9th, 2007, 10:50 PM
SQLScott's Avatar
Wrox Author
 
Join Date: Dec 2004
Location: Wellington, FL , USA.
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
Reply With Quote
  #3 (permalink)  
Old July 14th, 2007, 06:37 PM
Registered User
 
Join Date: Oct 2003
Location: , , .
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

Reply With Quote
  #4 (permalink)  
Old July 16th, 2007, 03:04 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
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
Reply With Quote
  #5 (permalink)  
Old July 25th, 2007, 11:43 AM
Registered User
 
Join Date: Oct 2003
Location: , , .
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.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 05:08 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.