locked
Basic Syntax Problem RRS feed

  • Question

  • Hey all,

    I'm new to Transact-SQL. Every time I go to save this procedure in VS2010 I get the following error: incorrect syntax near @result. I have no clue what I am doing wrong as everything looks okay to me from all the coding examples I have seen. Any help would be much appreciated.

    Thank you.

    ALTER PROCEDURE dbo.InsertDataLine
    (
    	@serialNumber nvarchar(25),
    	@dateTime smalldatetime,
    	@testName nvarchar(30),
    	@result nvarchar(12),
    	@units nvarchar(10),
    	@minValue nvarchar(12),
    	@maxValue nvarchar(12),
    	@passFail bit,
    	@channel nvarchar(3)
    )
    	
    AS
    
    DECLARE @temp nvarchar(20)
    
    IF @result = 'a' 
    	@result = 'b'
    ELSE
    	@result = 'c'
    END IF
    
    BEGIN
    
    			INSERT INTO [dbo].[tblTestResults] ([serialNumber], [dateTime], [testName], [result], [units], 
    						[minValue], [maxValue], [passFail], [channel]) 
    			VALUES (@serialNumber, @dateTime, @testName, @result, 
    					@units, @minValue, @maxValue, @passFail, @channel)
    
    	
    END
    


    Wednesday, June 15, 2011 2:38 PM

Answers

  • Try please :

    ALTER PROCEDURE dbo.InsertDataLine
    (
    @serialNumber nvarchar(25),
    @dateTime smalldatetime,
    @testName nvarchar(30),
    @result nvarchar(12),
    @units nvarchar(10),
    @minValue nvarchar(12),
    @maxValue nvarchar(12),
    @passFail bit,
    @channel nvarchar(3)
    )
    AS
    DECLARE @temp nvarchar(20)
    IF @result = 'a' 
    set @result = 'b' --use set for assignment
    ELSE
    set @result = 'c' --use set for assignment
    --END IF :: dont't use END IF 
    BEGIN
    INSERT INTO [dbo].[tblTestResults] ([serialNumber], [dateTime], [testName], [result], [units], 
    [minValue], [maxValue], [passFail], [channel]) 
    VALUES (@serialNumber, @dateTime, @testName, @result, 
    @units, @minValue, @maxValue, @passFail, @channel)
    END

     

     

     


    Best regards
    • Marked as answer by CoderRick Wednesday, June 15, 2011 2:45 PM
    Wednesday, June 15, 2011 2:41 PM
  • You need to precede assignment statements with the SET verb:

    IF @result = 'a'
      SET @result = 'b'
    ELSE
      SET @result = 'c'

    You must also remove the ENDIF

    Wednesday, June 15, 2011 2:40 PM

All replies

  • You have to set some value for @temp right after DECLARE @temp nvarchar(20) ,like

    set @result =some value
     


    Wednesday, June 15, 2011 2:40 PM
  • You need to precede assignment statements with the SET verb:

    IF @result = 'a'
      SET @result = 'b'
    ELSE
      SET @result = 'c'

    You must also remove the ENDIF

    Wednesday, June 15, 2011 2:40 PM
  • Try please :

    ALTER PROCEDURE dbo.InsertDataLine
    (
    @serialNumber nvarchar(25),
    @dateTime smalldatetime,
    @testName nvarchar(30),
    @result nvarchar(12),
    @units nvarchar(10),
    @minValue nvarchar(12),
    @maxValue nvarchar(12),
    @passFail bit,
    @channel nvarchar(3)
    )
    AS
    DECLARE @temp nvarchar(20)
    IF @result = 'a' 
    set @result = 'b' --use set for assignment
    ELSE
    set @result = 'c' --use set for assignment
    --END IF :: dont't use END IF 
    BEGIN
    INSERT INTO [dbo].[tblTestResults] ([serialNumber], [dateTime], [testName], [result], [units], 
    [minValue], [maxValue], [passFail], [channel]) 
    VALUES (@serialNumber, @dateTime, @testName, @result, 
    @units, @minValue, @maxValue, @passFail, @channel)
    END

     

     

     


    Best regards
    • Marked as answer by CoderRick Wednesday, June 15, 2011 2:45 PM
    Wednesday, June 15, 2011 2:41 PM
  • This worked perfectly, thank you!
    Wednesday, June 15, 2011 2:45 PM