Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQL:如何用两个替换一个?_Sql_Sql Server 2005_Replace_Line - Fatal编程技术网

SQL:如何用两个替换一个?

SQL:如何用两个替换一个?,sql,sql-server-2005,replace,line,Sql,Sql Server 2005,Replace,Line,我有一张“第一”桌: 我正试图写一个查询 If first.type = 'MM' then replace this line in two new lines where first.type = 'HH' and first.type = 'VV'. 例如:first.type='MM'所在的行: 我想这样替换这一行: 结果是: 有人知道如何做到这一点吗 我使用的是MS SQL Server Management Studio Express。此解决方

我有一张“第一”桌:

我正试图写一个查询

    If first.type = 'MM'

    then replace this line in two new lines

    where first.type = 'HH' and first.type = 'VV'.
例如:first.type='MM'所在的行:

我想这样替换这一行:

结果是:

有人知道如何做到这一点吗


我使用的是MS SQL Server Management Studio Express。

此解决方案可能非常具体,因为它意味着
类型
列只能有值
HH
MM
VV


select id,freq,parity,line,type,gain,obdim from [first] where type<>'MM'
union
select id,freq,parity,line,'HH' as type,gain,obdim from [first] where type='MM'
union
select id,freq,parity,line,'VV' as type,gain,obdim from [first] where type='MM'
SELECT
  f.ID,
  f.freq,
  f.parity,
  f.line,
  t.type,
  f.gain,
  f.obdim
FROM [first] f
  INNER JOIN (
    SELECT 'HH' AS type
    UNION ALL
    SELECT 'VV'
  ) t ON f.type IN (t.type, 'MM')

+1但请将*扩展到实际列中。一旦这个表被更新,一切都会崩溃。@Juronis:不知道为什么会出现这样的错误。不过,我稍微改变了一下,现在应该没问题了。也感谢你的评论,我注意到我的解决方案中有一个错误。也解决了。嗯,还是不行。我收到错误“查询输入必须至少包含一个表或查询”。您正在用什么RDBMS尝试此解决方案?是MS SQL Server还是MS Access?MS SQL Server,但我在MS Access中运行的这个示例。我将尝试使用MS SQL Server。
SELECT
  f.ID,
  f.freq,
  f.parity,
  f.line,
  t.type,
  f.gain,
  f.obdim
FROM [first] f
  INNER JOIN (
    SELECT 'HH' AS type
    UNION ALL
    SELECT 'VV'
  ) t ON f.type IN (t.type, 'MM')