Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.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 2008_Tsql - Fatal编程技术网

sql添加杂项字段

sql添加杂项字段,sql,sql-server-2008,tsql,Sql,Sql Server 2008,Tsql,我需要用户输入测试数据 我有以下字段: 范例 Blood Pulse ---- ----- 12 13 需要添加另一个字段,我们不知道测试的目的。 我在考虑有一个名为Misc1Label的字段,Misc1Value 如果Misc1Label是口头的,并且Misc1Value是88 稍后,若我们需要捕获Misc1Label的值,我可以使用Pivot,并使用Pivot,这样我就可以得到类似 Blood Pulse Oral ----- ---- ----

我需要用户输入测试数据 我有以下字段:

范例

 Blood   Pulse 
 ----    -----
 12      13
需要添加另一个字段,我们不知道测试的目的。 我在考虑有一个名为Misc1Label的字段,Misc1Value

如果Misc1Label是口头的,并且Misc1Value是88

稍后,若我们需要捕获Misc1Label的值,我可以使用Pivot,并使用Pivot,这样我就可以得到类似

 Blood  Pulse  Oral
 -----  ----   ----
   12    13     88
我在想,是否还有其他处理这个问题的最佳做法


提前感谢

您真的需要将血液和脉搏作为单独的字段保存吗?你可以把血液和脉搏视为不同的属性。听起来像这样的东西可以工作,并且不需要使用PIVOT命令就可以轻松地查询

PersonAttribute
    PersonId int (I'm only presuming here)
    AttributeId int

Attribute
    AttributeId int
    AttributeTypeId int
    AttibuteValue varchar(100)

AttributeType
    AttributeTypeId int
    AttributeType varchar(100)
然后,您可以将血液、脉搏、体重等存储在AttributeType表中,并使用PersonAttribute表作为主表的1-N方法。只是一个想法

SELECT Distinct PA.PersonId
FROM PersonAttribute PA
   INNER JOIN Attribute A ON PA.AttributeId = A.AttributeId 
   INNER JOIN AttributeType AT ON A.AttributeTypeId = AT.AttributeTypeId 
WHERE AT.AttributeType = 'Blood'
当然,如果需要的话,也可以使用相同的模型,将血液和脉搏留在主表中


祝你好运。

你真的需要将血液和脉搏作为单独的字段来保存吗?你可以把血液和脉搏视为不同的属性。听起来像这样的东西可以工作,并且不需要使用PIVOT命令就可以轻松地查询

PersonAttribute
    PersonId int (I'm only presuming here)
    AttributeId int

Attribute
    AttributeId int
    AttributeTypeId int
    AttibuteValue varchar(100)

AttributeType
    AttributeTypeId int
    AttributeType varchar(100)
然后,您可以将血液、脉搏、体重等存储在AttributeType表中,并使用PersonAttribute表作为主表的1-N方法。只是一个想法

SELECT Distinct PA.PersonId
FROM PersonAttribute PA
   INNER JOIN Attribute A ON PA.AttributeId = A.AttributeId 
   INNER JOIN AttributeType AT ON A.AttributeTypeId = AT.AttributeTypeId 
WHERE AT.AttributeType = 'Blood'
当然,如果需要的话,也可以使用相同的模型,将血液和脉搏留在主表中


祝你好运。

我做了一件事后才想到的事。我们得到了一些领域,如血液等设置+1。但我认为您应该显示一个聚合查询,该查询返回给定人员的所有值。我们得到了一些领域,如血液等设置+1。但是我认为您应该显示一个聚合查询,它返回给定人员的所有值。