将列值分隔为两列作为记录

时间:2016-09-13 09:47:39

标签: sql sql-server sql-server-2008

我想得到表B.如何在MSSQL中编写选择查询

enter image description here

enter image description here

3 个答案:

答案 0 :(得分:0)

您可以使用存储过程复制另一个表中的记录。

CREATE PROCEDURE [dbo].[CopyRecords]
(@TableBID int)
AS
BEGIN
INSERT INTO [TableB]
    ([EffectiveDate],[EmployeeName],
    [Title],[Department]) --- Columns of TableB table

SELECT [EffectiveDate],[EmployeeName],
    [FieldValue],[FieldType] ---Columns of TableA table
FROM [TableA]
WHERE TableAID = @TableBID --- Where value of TableAID of TableA table matches the value of @TableAID
END

答案 1 :(得分:0)

您可以通过条件聚合来实现这一目标。

    SELECT [EFFECTIVE DATE],[EMPLOYEE NAME],
    MAX(CASE WHEN FieldType = 'Title' THEN FIELDVALUE end) as Title,
    MAX(CASE WHEN FieldType = 'Department' THEN FIELDVALUE end )as department
    from table_a group by [EMPLOYEE NAME],[EFFECTIVE DATE]

答案 2 :(得分:0)

buttonMediaPressed = function(clicked_btn_id) {
  console.log("In buttonMediaPressed function :- " + clicked_btn_id);
  var circle = $('#' + clicked_btn_id + ' .circle');
  if (!circle.length) {
    $('#' + clicked_btn_id).append('<div class="circle"></div>');
    circle = $('#' + clicked_btn_id + ' .circle');
  }
  setTimeout(function() {
    circle.toggleClass('open');

  })
  setTimeout(function() {
    //change image back
    circle.toggleClass('open');

  }, 300);
}