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 April 19th, 2006, 02:42 AM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default Please check my SP

The following SP is not executing properly (doesnt do the inserts however does the updates) FYI we are connecting during testing usignt he SA account to eliminate permission problems:

CREATE PROCEDURE sp_UpdateCourse
(
    @Code int,
    @Description varchar(72),
    @School varchar(64),
    @MaxStudents int,
    @CourseDuration real,
    @MinRank varchar(3),
    @maxRank varchar(3),
    @Inactive bit
)
AS
    DECLARE @MinSeq int
    DECLARE @MaxSeq int
    DECLARE @code2 int
    DECLARE @Seq int
    DECLARE @Rank varchar(3)

    IF @MinRank IS NULL
        SET @MinSeq = 100
    ELSE
        SET @MinSeq = (SELECT SeqOrder FROM Ranks WHERE Code = @MinRank)
    IF @MaxRank IS NULL
        SET @MaxSeq = 0
    ELSE
        SET @MaxSeq = (SELECT SeqOrder FROM Ranks WHERE Code = @MaxRank)
    IF @MinSeq < @MaxSeq
    BEGIN
        SET @Seq = @MinSeq
        SET @MinSeq = @MaxSeq
        SET @MaxSeq = @Seq
        SET @Rank = @MinRank
        SET @MinRank = @MaxRank
        SET @MaxRank = @Rank
    END

    SET @Code2 = (SELECT Code FROM Courses WHERE Code = @Code)
    IF ((@Code2 = null) OR ( @Code2 <> @Code))
        INSERT INTO Courses (Code, Description, School,MaxStudents,
            CourseDuration, MinRank, MaxRank,MinSeq,MaxSeq, Inactive,Updated)
        VALUES (@Code,@Description,@school, @MaxStudents,
            @CourseDuration,@minRank,@maxRank,@MinSeq,@MaxSeq, @Inactive,1)
    ELSE
        UPDATE Courses SET
            Description = @Description,
            School = @school,
            MaxStudents = @MaxStudents,
            CourseDuration = @CourseDuration,
            MinRank = @MinRank,
            MaxRank = @MaxRank,
            MinSeq = @MinSeq,
            MaxSeq = @MaxSeq,
            Inactive = @Inactive,
            Updated = 1
            WHERE Code = @Code
GO


BTW: I dont write to many SP's. I have a couple of questions:

1..When I click the 'Check Syntax' button it is problem free. Why If I change a table name to be incorrect (table does not exist) does it still say problem free?

2..If I change a variable name or field name it says there is a problem

This SP gets executed in line in an ASP page. I hope I have given all required information.

TYIA


Wind is your friend
Matt
__________________
Wind is your friend
Matt
 
Old April 19th, 2006, 05:36 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

First off, you cannot test whether something is equal to NULL. Nothing is ever equal to NULL, or not equal to NULL, for that matter. Any comparison whatsoever to NULL will always fail, i.e. be interpreted as false.

You must test to see if something is NULL. An annoying distinction, perhaps, but there it is. Thus, your line in the IF which controls execution of the INSERT statement should read:

IF ((@Code2 IS NULL) OR ( @Code2 <> @Code))

(It's curious that you constructed the other prior tests for NULL correctly.)

As to your other questions:

The 'Check Syntax" button is unfortunately just that, a syntax check. It will find syntax errors in your SP, such as missing commas, parentheses, undeclared variables, etc. It will not find semantic errors, though, such as whether a database object actually exists. Those won't be detected until the SP is compiled, right before it is run.



Jeff Mason
Custom Apps, Inc.
www.custom-apps.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to check programmatically check the password? thomaskelly ASP.NET 1.0 and 1.1 Basics 1 May 16th, 2008 08:49 PM
Connect to VSS check-in Check-out Programatically rhd110 General .NET 6 August 12th, 2007 07:46 AM
exec sp within another sp collie SQL Server 2000 1 December 22nd, 2004 05:46 AM
Can a SP run another SP as sa? dbradley SQL Server 2000 0 July 17th, 2003 08:35 AM





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