Home > Archive > Microsoft SQL Server forum > February 2006 > select statement returns null in stored proc









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author select statement returns null in stored proc
Beowulf

2006-02-25, 9:44 am

If I run this statement in Query Analyzer, it properly returns 1
for my testing table. But if I put the statement into a stored
procedure, the stored procedure returns NULL. What am I doing
wrong? I suspect it may be related to how I defined the parameters
for the stored procedure. Perhaps my definition of TableName and
ColumnName don't match what COLUMNPROPERTY and OBJECT_ID expect to
receive, but I don't know where to look for the function declarations
for those. Any pointers would be appreciated.

Select statement:
SELECT COLUMNPROPERTY(OBJEC
T_ID('Table1'), 'TestID', 'IsIdentity') AS
IsIdentity

Table definition:
CREATE TABLE [dbo].[Table1] (
[TestID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,
[Description] [varchar] (50) COLLATE SQL_Latin1_General_C
P1_CI_AS NOT NULL
) ON [PRIMARY]

Stored Procedure definition:
CREATE PROCEDURE spTest
(@TableName varchar,
@ColumnName varchar)
AS SELECT COLUMNPROPERTY(OBJEC
T_ID(@TableName), @ColumnName,
'IsIdentity') AS IsIdentity
markc600@hotmail.com

2006-02-25, 9:44 am

You need to specify lengths for your varchar parameters

CREATE PROCEDURE spTest
(@TableName varchar(50),
@ColumnName varchar(50))

Beowulf

2006-02-25, 9:44 am

markc600@hotmail.com wrote:
> You need to specify lengths for your varchar parameters
>
> CREATE PROCEDURE spTest
> (@TableName varchar(50),
> @ColumnName varchar(50))


That was it. Thanks.
Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com