Stored Procedure Syntax

  • I'm new to SQL and Stored procedures. I'm trying to write a stored procedure and I'm having difficulty with the syntax. Ultimately what needs to happen is that if a certain condiion is met, then a variable will add one to it's initial value of 0 until the procedure has gone through the table basically counting the number of times a condition was met. There will be three specific conditions and three different variables counting the number of times a specific condition is met. Then the values of the variables will be printed out. If anyone has an idea for the syntax I'd appreciate it.

  • How about posting what you have for code so far?

    One thing to strive for is set based operations, not cursor. Sounds like you need to run either 3 count queries, or one select with a group by and having to get your totals. Then you have to decide if you want to return 3 recordsets, 1 recordset, or 3 output parameters. 'Printing' the results in a proc is good only for debugging, not for production.

    Andy

  • If you are calling a stored proc recursively, you an define a parameter as an OUTPUT parameter and include it on all subsequent calls. When the outermost proc completes, it will have the value of your count.

    But I agree, you should use a select count(*) where ...

    to get your counts. Easier and faster.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply