Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 If statement

Author  Topic 

shonre89
Starting Member

5 Posts

Posted - 2014-07-01 : 03:16:14
i have two conditions to check for.
1st condition is to check if status is FINISHED then update OK
2nd condition is to check if status is LOADING_BY_LINE then update ONGOING

I manage to do it for one but i could not get the syntax right on the if statement

UPDATE f
SET Inspector_Status = 'OK'
FROM FM_SHARE_RO_MOVED f
WHERE EXISTS
(
SELECT *
FROM PARSE_FILE_DETAILS
WHERE File_Location LIKE '%' + f.File_name + '%' and STATUS ='FINISHED'
)



-SHON-

ahmeds08
Aged Yak Warrior

737 Posts

Posted - 2014-07-01 : 04:55:22
can you try this

update f set Inspector_Status =
case when status='FINISHED' then 'OK'
when status='LOADING_BY_LINE' then 'ONGOING'
else 'something'

Javeed Ahmed
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2014-07-01 : 05:43:01
[code]UPDATE f
SET f.[Inspector_Status] = CASE x.[Status]
WHEN 'FINISHED' THEN 'OK'
WHEN 'LOADING_BY_LINE' THEN 'ONGOING'
ELSE f.[Inspector_Status]
END
FROM dbo.FM_SHARE_RO_MOVED AS f
LEFT JOIN dbo.PARSE_FILE_DETAILS AS x ON x.File_Location LIKE '%' + f.[File_name] + '%';[/code]


Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page

shonre89
Starting Member

5 Posts

Posted - 2014-07-07 : 04:25:06
THANK YOU VERY MUCH. IT WORKS FINE
quote:
Originally posted by SwePeso

UPDATE		f
SET f.[Inspector_Status] = CASE x.[Status]
WHEN 'FINISHED' THEN 'OK'
WHEN 'LOADING_BY_LINE' THEN 'ONGOING'
ELSE f.[Inspector_Status]
END
FROM dbo.FM_SHARE_RO_MOVED AS f
LEFT JOIN dbo.PARSE_FILE_DETAILS AS x ON x.File_Location LIKE '%' + f.[File_name] + '%';



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA



-SHON-
Go to Top of Page
   

- Advertisement -