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 3rd, 2008, 10:58 PM
Registered User
 
Join Date: Jan 2008
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default error in query

tis sp insert time in the database .if it exit in the db it rasie
error other wise it insert the new time evert time
but it give error on 2 Statement "Begin "

some one help me to recover error



CREATE PROCEDURE InsertTiming(@timing nvarchar(255))
BEGIN
  SET NOCOUNT ON;

  -- Check if timing already exists
  DECLARE @tmp nvarchar(255);
  SELECT @tmp = s_time FROM timing WHERE s_time = @timing;
  IF @tmp IS NOT NULL
  BEGIN
    raiserror(N'Timing %s already assigned',
      10,
      1,
      @timing);
  END

  -- Insert new value
  INSERT INTO timing(s_test) VALUES (@timing);
END


 
Old April 3rd, 2008, 11:18 PM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

CREATE PROCEDURE InsertTiming(@timing nvarchar(255))
AS
BEGIN
  SET NOCOUNT ON;

  -- Check if timing already exists
  DECLARE @tmp nvarchar(255);
  SELECT @tmp = s_time FROM timing WHERE s_time = @timing;
  IF @tmp IS NOT NULL
  BEGIN
    raiserror(N'Timing %s already assigned',
      10,
      1,
      @timing);
  END

  -- Insert new value
  INSERT INTO timing(s_test) VALUES (@timing);
END


--Jeff Moden
 
Old April 4th, 2008, 12:29 AM
Registered User
 
Join Date: Jan 2008
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i use As before begining
it give me error on

 @timing

 
Old April 4th, 2008, 01:14 AM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

Please... print the actual error you get so I can see things like line numbers and error codes.

--Jeff Moden
 
Old April 4th, 2008, 01:18 AM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

You really need to check Books Online for syntax... in the mean time, I thing the problem is that you put parenthesis around the input paramter... remove those and you should be good to go. Also, for the sake of brevity, you can remove the outer BEGIN and the RELATED end... they are not required in SQL Server.

--Jeff Moden
 
Old April 4th, 2008, 01:27 AM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

Here's how I'd write the code... dunno if the tables and column names are correct because you didn't list the CREATE TABLE statement for any of the tables...
Code:
 CREATE PROCEDURE dbo.InsertTiming 
        @Timing NVARCHAR(255)
     AS
    SET NOCOUNT ON

     IF EXISTS (SELECT S_Time FROM dbo.Timing WHERE S_Time = @Timing)
  BEGIN --Alert the operator if the timing already exists
        RAISERROR(N'Timing %s already assigned',10,1,@Timing)
    END
   ELSE
  BEGIN --Timing does not exist... insert new timing value
        INSERT INTO dbo.timing(S_Test) VALUES (@Timing)
    END
--Jeff Moden





Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert Query Error & Run-Time Error 3022 DavidWE Access 1 July 31st, 2008 11:17 AM
Query Error Louisa VB.NET 2002/2003 Basics 5 August 9th, 2006 03:44 AM
error in query beetle_jaipur SQL Server 2000 9 April 4th, 2006 02:16 AM
Syntax error in query. Incomplete query clause. dispickle ADO.NET 3 April 16th, 2004 01:04 PM
Error on Make-Table Query In Union Query rylemer Access 1 August 20th, 2003 07:42 PM





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