question

Nani avatar image
Nani asked

problem with userdefined functions

CREATE FUNCTION dbo.ValidSerialNumber( @nvcSerialNumber nvarchar(50))

RETURNS BIT
AS

BEGIN

DECLARE
@bValid 	BIT,

    --default to invalid serial number
    SET @bValid = 0


    IF @nvcSerialNumber LIKE '[0-9][A-Z][0-9][A-Z][0-9][0-9][0-9][0-9]'
    BEGIN
    	SET @bValid = 1
    END


    IF @nvcSerialNumber LIKE '[0-9][0-9][0-9][A-Z][0-9]5[A-Z]'
    BEGIN
          SET @bValid = 1
    END

RETURN ( @bValid)

END

This code is showing Following error. Why?

Msg 156, Level 15, State 1, Procedure ValidSerialNumber, Line 10
Incorrect syntax near the keyword 'SET'

.

sql-server-2005user-defined-function
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Håkan Winther avatar image
Håkan Winther answered

If you have copied the code into this question, then you have an extra ,

DECLARE @bValid BIT,

Change to

DECLARE @bValid BIT
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.