I'm not familiar with the format
'${state.Objektiv}'
- that is not how variables are used in MSSQL. See
Variables (Transact-SQL) | Microsoft Docs[
^].
The
$
symbol isn't listed as a Symbol that would be used in MSSQL -
SQL Symbol Cheat Sheet[
^]
Does this example help you -
declare @tblFoto table (Bildnr int)
declare @state_Objektiv varchar(255) = 'Fahrzeugdatenträger'
declare @Bildnummer int
set @Bildnummer = (SELECT
CASE @state_Objektiv
WHEN 'vorne rechts' THEN 2
WHEN 'vorne links' THEN 3
WHEN 'hinten rechts' THEN 4
WHEN 'hinten links' THEN 5
WHEN 'Innenraum' THEN 6
WHEN 'Navigationsgerät' THEN 7
WHEN 'Kombiinstrument' THEN 8
WHEN 'Fahrzeugdatenträger' THEN 9
WHEN 'Servicenachweis' THEN 10
ELSE 11
END)
insert into @tblFoto (Bildnr) values (@Bildnummer)
select * from @tblFoto
EDIT - @Naga-Sindhura has pointed out that that is a long list of conditions that are probably better handled using a table variable. e.g.
declare @references table (Beschreib nvarchar(255), bildnr int)
insert into @references (Beschreib, bildnr) values
('vorne rechts', 2),
('vorne links', 3),
('hinten rechts', 4),
('hinten links', 5),
('Innenraum', 6),
('Navigationsgerät', 7),
('Kombiinstrument', 8),
('Fahrzeugdatenträger', 9),
('Servicenachweis', 10)
Note I have not added an entry for the ELSE condition (11).
Then you can do something like
declare @tblFoto table (Bildnr int)
declare @state_Objektiv varchar(255) = 'FahrzeugdatenträgerXXX'
declare @Bildnummer int = (SELECT bildnr from @references WHERE Beschreib = @state_Objektiv)
insert into @tblFoto (Bildnr) values (ISNULL(@Bildnummer,11))
select * from @tblFoto
Notice the use of
ISNULL
to handle what was the ELSE condition