In your case, End is missing
Case when (something) then (Some) else (another thing) end
In any case, your else should return select, the insert will not return anything. if you want to insert, if it doesnβt exist, then return the inserted value (or return if it exists) do the following:
INSERT INTO Domains(Domain_ID,Domain,Disabled,Description) VALUES(@Domain_ID,@Domain,@Disabled,@Description) where not exists (select 1 from Domains WHERE Domain = @domain); SELECT Domain_ID FROM Domains WHERE Domain = @domain
This will be inserted if it does not exist, and then return. If it already exists, it will not be inserted and returns a value
Change January 2016
The last query will not work on MySql , this is the MSSQL syntax
source share