首页 \ 问答 \ SQL Server:根据记录的值返回列名称(SQL Server : return column names based on a record's value)

SQL Server:根据记录的值返回列名称(SQL Server : return column names based on a record's value)

根据以下示例表,我希望有人对以下内容有一个快速建议/解决方案:

|Field1 |Field2 |Field3 |Field4 |
|-------|-------|-------|-------|
| 1     | 0     | 0     | 1     |

我希望能够建立一个查询来返回其值(基于单个记录)= 1的列名。这不依赖于游标或临时表。

即我想要以下输出:

Field1
Field4

我一直在尝试对sys.columns (和sys.tables )进行各种连接,但目前为止没有效果。


I'm hoping someone has a quick suggestion/solution to the following, based on the following sample table:

|Field1 |Field2 |Field3 |Field4 |
|-------|-------|-------|-------|
| 1     | 0     | 0     | 1     |

I was hoping to be able to build a query to return the column names where their value (based on a single record) = 1. This, without leaning on cursors or temp tables.

I.e. I would like the following output:

Field1
Field4

I've been trying to do various joins against sys.columns (and sys.tables), but so far to little avail.


原文:https://stackoverflow.com/questions/27285569
更新时间:2023-02-07 06:02

最满意答案

我需要运行您的示例以确保可能,但以下可能会有所帮助。

不要摧毁图表,你可以添加和删除数据集,

  • 在添加新数据之前删除数据集

    data.labels = []; //Empty label array
    data.datasets.splice(0, 1);//Removes first dataset
    
  • 添加新的数据集和标签

  • 更新图表

    pauzeAmountChart.update();
    

我有一个工作示例,它从webapi检索新数据并每10秒更新一次,如果这不够用的话


I would need to run your example to be sure but maybe the following would help.

Instead of destroying the chart you can add and remove datasets,

  • Remove dataset before adding new data

    data.labels = []; //Empty label array
    data.datasets.splice(0, 1);//Removes first dataset
    
  • Add new dataset and labels

  • Update chart

    pauzeAmountChart.update();
    

I have a working example which retrieves new data from a webapi and updates every 10 seconds, if this isnt sufficient

相关问答

更多
  • 实际上有几种方法可以实现这一目标。 为简单起见,我将修改您提供的示例。 请记住,这会将标签放在栏内。 您可以轻松地修改它以将其放在外面,但您必须添加逻辑以确保不会溢出图表顶部或其他条形图(不是非常简单的逻辑)。 此外,此方法要求您为每个数据集配置标签(无论如何都需要驱动常规图例)。 只需将它放在animation.onComplete属性中即可。 function() { var ctx = this.chart.ctx; ctx.font = Chart.helpers.fontString(Ch ...
  • 这是我在发布问题后再次尝试使其工作的方式。 function drawChart() { var cur = Categories.find(); collData = []; cur.forEach(function(cat){ collData.push([cat.value]); }); collLabel = []; cur.forEach(function(cat){ collLabel.push([cat.cat ...
  • 那么,我猜你正在使用API来获取你的数据? 然后你需要检查数据是否可用。 Axios / Ajax请求是异步的。 所以大部分时候,你的图表都会被渲染而没有数据。 只需在图表组件和您的图表组件上添加v-if =“loaded” axios.get()。then()方法,设置loaded = true,你应该没问题。 Well, I guess you are using an API to get your data? Then you need to check if the data is availab ...
  • 我需要运行您的示例以确保可能,但以下可能会有所帮助。 不要摧毁图表,你可以添加和删除数据集, 在添加新数据之前删除数据集 data.labels = []; //Empty label array data.datasets.splice(0, 1);//Removes first dataset 添加新的数据集和标签 更新图表 pauzeAmountChart.update(); 我有一个工作示例,它从webapi检索新数据并每10秒更新一次,如果这不够用的话 I would need to run ...
  • 您构建图表的方法完全不合适。 这是正确的方法,你应该遵循: var jsonfile = { "jsonarray": [{ "name": "Joe", "age": 12 }, { "name": "Tom", "age": 14 }] }; var labels = jsonfile.jsonarray.map(function(e) { return e.name; }); var data = js ...
  • 您需要将title对象包装在options对象中 var myChart = new Chart(ctx, { type: 'doughnut', options: { title: { display: true, text: 'TEST' } } .... 以下是所有选项的完整列表的文档, chartjs:title var data = [2137680, 6282693, 805566, 25 ...
  • 使用您正在采用的方法(例如,每次日期范围更改时创建一个新的Chart对象),那么您必须首先销毁先前的图表,然后创建新的图表。 您可以使用.destroy()原型方法来执行此操作。 这正是API所说的。 使用它来销毁任何创建的图表实例。 这将清除Chart.js中存储到Chart对象的所有引用以及Chart.js附加的任何关联事件侦听器。 这必须在画布重新用于新图表之前调用。 因此,你的代码看起来像这样(注意我们销毁并重新创建)。 // define a variable to store the chart ...
  • 如果这是您拥有的唯一图表(即因为以下代码更改了某些全局chart.js元素),您可以使用以下代码 var originalMultiTooltip = Chart.MultiTooltip; Chart.MultiTooltip = function () { var argument = arguments[0]; // locate the series using the active point var activeDatasetLabel = myChart.activeE ...
  • 设置myChart["config"]["data"] = data2 // Supplied Datasets to display var data1 = { "labels": ["1", "2", "3"], "datasets": [{ "label": "Contacts", "data": [20, 15, 10], "backgroundColor": "rgba(255, 99, 132, 0.2)", "borderColor": "rgba(255,99,132,1)", "bord ...
  • 自定义工具提示选项用于在想要使用画布范围之外的HTLM / CSS创建/设置自己的工具提示时(并且根本不使用内置工具提示)。 为此,您必须在画布之外定义一个位置以包含工具提示(例如div ),然后在tooltips.custom函数中使用该容器。 下面是一个示例,我使用自定义工具提示在图表中间显示悬停的饼图部分百分比。 在这个例子中,我在id为“chartjs-tooltip”的div生成我的工具提示。 请注意我在tooltips.custom函数中如何与此div交互以定位和更改值。 此外,检查是否应隐藏工 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)