简体   繁体   中英

Adding addition logic to a stored procedure

Im working in a stored procedure where i need to update its function.

The Stored proc insert data to a table and add a 0 flag and we run a batch it will set the flag to 1 saying the record were already processed.

I am editing the stored proc to always insert a 1 flag to specific record so it would not be process.

The code work like this

INSERT INTO [dbo].[personel]
        ([FirstName]
        ,[LastName]
        ,[IdNo]
        ,[ProcessedIndicator]
        ,[CreateDate]
Select AP.FirstNm
    ,AP.LastNm
    ,AP.Idno
    ,CASE 0
       WHEN AP.Locotion = '' AND AP.Position 0001 BETWEEN  AND 0005 
         THEN insert 1
       ELSE '0'
     END    
    ,GetDate()
from dbo.AllPersonel AS AP

Your CASE statement has several syntax (and spelling) problems. Try this:

CASE
    WHEN AP.Location = '' AND AP.Position BETWEEN 0001 AND 0005 THEN 1
    ELSE '0'
END

The CASE statement has two flavours:

CASE someExpression
    WHEN someValue THEN someResult
    ...
    ELSE someDefault
END

or

CASE
    WHEN someCondition THEN someResult
    ...
    ELSE someDefault
END

You were trying to mix the two forms.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM