I'am using Microsoft SQL Server, and was wandering if its possible to create a condition inside a procedure that will check for a string value, and replace it.
For example something like,
if [column name] = 'Adam'
then [column name] = 'BoB'
when a.TYPEID = 2 THEN
-- condition / change name
From some_table a
case constructs can be nested, see here:
SELECT a.projectName, a.user, Case when a.TYPEID = 2 THEN concat(a.[MESSAGE] , Case a.Name when 'Adam' Then 'Bob' else a.Name end) End msg From some_table a
This is assuming that you want to concat the optionally changed name to the MESSAGE. Concatenation can also be done by using the
+ operator in sql-server.
It is not quite clear from your question what you want to happen, if
TYPEID != 2. Currently nothing (
null) gets output.