Wrox Programmer Forums
|
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 August 25th, 2006, 10:16 AM
Authorized User
 
Join Date: Jun 2003
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default help syntax please

I have the following codes, when running I got the syntax error:
"Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'output'."

Please help me, what did I do wrong or miss?

CREATE PROCEDURE Cmd_ConsoleCounter
  (
@TableName varchar(255),
@Col varchar(255),
@value varchar(255) ,
@RecCount int = null output
  )
AS

    DECLARE @SQLStatement varchar(255)

    SELECT @SQLStatement = 'SELECT Count(*) FROM ' + @TableName + ' Where ' + @col + ' = ' + CHAR(39) + @value + CHAR(39)+ ' output '

-- EXEC @RecCount=@SQLStatement
 EXEC (@SQLStatement)
GO


Thanks a lot!

 
Old August 26th, 2006, 02:47 AM
Authorized User
 
Join Date: Mar 2006
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi khautinh!

The output keyword added in your statement is producing error-

SELECT @SQLStatement = 'SELECT Count(*) FROM ' +
@TableName + ' Where ' + @col + ' = ' + CHAR(39) +
@value + CHAR(39)+ ' output '

There is no statement like this. If you are keen to get the rowcount, you can use @@rowcount function. Something like this -

@RecCount=@@rowcount

So, remove the output statement and based on your procedure, the final procedure would be
(With some other modifications) -

--------------------------------

Create PROCEDURE Cmd_ConsoleCounter

@TableName varchar(255),
@Col varchar(255),
@value varchar(255) ,
@RecCount int output
AS

DECLARE @SQLStatement varchar(255)

SELECT @SQLStatement = 'SELECT * FROM ' + @TableName + ' Where ' + @col + ' = ' + CHAR(39) + @value + CHAR(39)

EXEC (@SQLStatement)
SET @RowCount=@@ROWCOUNT
GO

--------------------------------

This would select the table and also tell you no. of rows selected. The modification are as follows -

1. Parameters were in parenthesis.Used only with UDFs. No need to place them.

2. @RecCount int = null output : No need to intialize with null. @@ROWCOUNT if does not selects any row, 0 would be placed. One more thing null and 0 have lots of differences. (u must be known of it)

3. output at the end of select statment is syntax error.

4. Adding Set @RowCount=@@ROWCOUNT would output the no. of rows selected.

That's it. Try it out and do not forget to reply whether it worked or not.


- Som Dutt
---------------------------
http://doeaccpapers.com
http://somdutt.blogspot.com








Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with Query Syntax [email protected] SQL Language 1 May 1st, 2007 06:42 AM
syntax error Adam H-W Classic ASP Basics 3 December 12th, 2006 08:20 AM
Syntax Error Cinderella Classic ASP Basics 4 February 1st, 2005 05:13 PM
Syntax and formatting Help michanne XSLT 0 January 26th, 2005 01:24 PM
c# syntax msrnivas .NET Web Services 2 October 15th, 2004 01:26 AM





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