" case"附近的语法不正确

时间:2017-12-18 16:08:05

标签: sql-server sql-server-2016

我有一个表有这样的数据:

 ID | Fill
  ---------------
  1  |  @@@@
  2  |  @@@@Y
  3  |  @@@@Y245

我想将上述数据插入到另一个表中,并期望结果表为:

  ID | Fill
  ----------------
  1  |      (Space)
  2  |      Y
  3  |      Y245

也就是说,当我找到@@@@时,应该用空格替换(4个空格字符,因为它有4个@)

以下是我尝试这样做的方法:

   insert into table1
    (
   id

   ,case
       when contains(substring([fill],1,4),'@@@@') then '    '+substring([fill],5,100)
       else [fill]
       end 
    )
    select
    id
   ,convert(char(100),[col1]+[col2]+[col3]+[col4])
      from 
     table2

然而,它在" case"附近显示语法错误。我究竟做错了什么?我怎样才能达到预期的效果?

2 个答案:

答案 0 :(得分:2)

只需使用library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity shrink_func is port ( clk : in std_logic; rst : in std_logic; maj : in std_logic_vector(31 downto 0); ch : in std_logic_vector(31 downto 0); sig0 : in std_logic_vector(31 downto 0); sig1 : in std_logic_vector(31 downto 0); k : in std_logic_vector(31 downto 0); ward : in std_logic_vector(31 downto 0); digest : out std_logic_vector(255 downto 0)); end; architecture shrink_func of shrink_func is signal ready : std_logic := '0'; signal h0 : std_logic_vector(31 downto 0) := x"6a09e667"; signal h1 : std_logic_vector(31 downto 0) := x"bb67ae85"; signal h2 : std_logic_vector(31 downto 0) := x"3c6ef372"; signal h3 : std_logic_vector(31 downto 0) := x"a54ff53a"; signal h4 : std_logic_vector(31 downto 0) := x"510e527f"; signal h5 : std_logic_vector(31 downto 0) := x"9b05688c"; signal h6 : std_logic_vector(31 downto 0) := x"1f83d9ab"; signal h7 : std_logic_vector(31 downto 0) := x"5be0cd19"; signal t1 : std_logic_vector(31 downto 0) ; signal t2 : std_logic_vector(31 downto 0) ; signal a,b,c,d,e,f,g,h : std_logic_vector(31 downto 0) ; signal temp : std_logic_vector(255 downto 0); begin process (clk,rst) variable i : integer; begin if rst = '0' then i := 0; a <= h0; b <= h1; c <= h2; d <= h3; e <= h4; f <= h5; g <= h6; h <= h7; temp <= x"0000000000000000000000000000000000000000000000000000000000000000"; t1 <= x"00000000"; t2 <= x"00000000"; elsif clk'event and clk = '1' then if i = 64 then i := 0; ready <= '1'; a <= h0; b <= h1; c <= h2; d <= h3; e <= h4; f <= h5; g <= h6; h <= h7; temp <= x"0000000000000000000000000000000000000000000000000000000000000000"; t1 <= x"00000000"; t2 <= x"00000000"; end if; if ready = '1' then temp <= a & b & c & d & e & f & g & h; end if; ready <= '0'; i := i+1; t1 <= h + sig1 + ch + k + ward; t2 <= sig0 + maj; end if; end process; process(t1, t2, h, g, f, e, d, c, b, a) begin h <= g; g <= f; f <= e; e <= d + t1; d <= c; c <= b; b <= a; a <= t1 + t2; end process; digest <= temp; end;

即可
replace()

如果发生insert into destination_table (col1) select replace(col1, '@', ' ' ) from source_table ,则会被替换。如果没有,则使用原始字符串。

答案 1 :(得分:0)

该案例位于INSERT语句的字段列表部分,因此无效。 你可以使用一个简单的替换来实现这个

get_map