coalesce

In your opinion what is more readable: ?? (operator) or use of if's

萝らか妹 提交于 2019-12-02 00:30:40
问题 I have a method that will receive a string , but before I can work with it, I have to convert it to int . Sometimes it can be null and I have to change its value to "0" . Today I have: public void doSomeWork(string value) { int SomeValue = int.Parse(value ?? "0"); //it can throw an exception(i know) } I did it, but my boss asked me to refactor it to: public void doSomeWork(string value) { if(string.IsNullOrEmpty(value)) value = "0"; int SomeValue = int.Parse(value); } in your opinion what is

Coalesce and Concat in the same statement, Postgres

人走茶凉 提交于 2019-12-01 22:31:19
问题 I am trying to concat an individual's first and last name together but coalesce a team name when there is a null value. Unfortunately my syntax is returning a SPACE, so coalesce does not recognize it as a null value.. What can I do to correct this? Syntax I am currently using: coalesce((Concat(first_name,' ',last_name)),team_name) 回答1: Just use the concatenation operator, || : coalesce(first_name || ' ' || last_name, team_name) The concat() function ignores NULL values. The operator returns

LINQ to SQL C# COALESCE

落爺英雄遲暮 提交于 2019-12-01 22:25:20
Given the following table: Length | Width | Color | ID =========================== 18 | 18 | blue | 1 --------------------------- 12 | 12 | red | 1 --------------------------- I want to produce a single column/row: SIZES ================= 18 x 18, 12 x 12, I can do this in SQL as follows: DECLARE @SIZES VARCHAR(8000) SELECT @SIZES = COALESCE(@SIZES, '') + Convert(varchar(80), [Length]) + ' x ' + Convert(varchar(80), [Width]) + ', ' FROM table where ID = 1 GROUP BY [Length], [Width] ORDER BY [Length], [Width] SELECT SIZES = @SIZES But I cannot figure out how to do this in LINQ. The closest I

Coalesce and Concat in the same statement, Postgres

倾然丶 夕夏残阳落幕 提交于 2019-12-01 21:29:26
I am trying to concat an individual's first and last name together but coalesce a team name when there is a null value. Unfortunately my syntax is returning a SPACE, so coalesce does not recognize it as a null value.. What can I do to correct this? Syntax I am currently using: coalesce((Concat(first_name,' ',last_name)),team_name) Just use the concatenation operator, || : coalesce(first_name || ' ' || last_name, team_name) The concat() function ignores NULL values. The operator returns NULL . 来源: https://stackoverflow.com/questions/41770098/coalesce-and-concat-in-the-same-statement-postgres

In your opinion what is more readable: ?? (operator) or use of if's

99封情书 提交于 2019-12-01 20:29:21
I have a method that will receive a string , but before I can work with it, I have to convert it to int . Sometimes it can be null and I have to change its value to "0" . Today I have: public void doSomeWork(string value) { int SomeValue = int.Parse(value ?? "0"); //it can throw an exception(i know) } I did it, but my boss asked me to refactor it to: public void doSomeWork(string value) { if(string.IsNullOrEmpty(value)) value = "0"; int SomeValue = int.Parse(value); } in your opinion what is the best option? Personally I'd go for the corrected version of your bosses - possibly with even more

SQL - Ugly combination of GROUP BY and COALESCE

大兔子大兔子 提交于 2019-12-01 18:10:24
问题 I have a table with data similar to the following: [ID], [State], [foo], [DateCreated], [DateUpdated] The longer I work on this, the uglier my SQL is getting, which tells me I'm probably doing something wrong. What I want is a unique list of each State so long as foo is always the same for that State (if foo is not the same for all records in that State, I don't want that State at all) . Also, I want to COALESCE DateCreated and DateUpdated and want the maximum value for that State. So given

MySQL, multiple rows to separate fields

你。 提交于 2019-12-01 18:00:17
I have a MySQL table with fields and data such as follows; PartNumber Priority SupName a1 0 One a2 0 One a2 1 Two a3 0 One a4 1 Two a5 2 Three I am trying to create a view where the parts that have multiple rows are combined into a single row, and into separate fields such as Ideally This; PartNumber Sup1 Sup2 Sup3 a1 One NULL NULL a2 One Two NULL a3 One NULL NULL a4 Two NULL NULL a5 Three NULL NULL Or I can live with this PartNumber Sup1 Sup2 Sup3 a1 One NULL NULL a2 One Two NULL a3 One NULL NULL a4 NULL Two NULL a5 NULL NULL Three How would I build a view or select statement to accomplish

缺失索引自动创建语句(转)

Deadly 提交于 2019-12-01 16:06:37
缺失索引自动创建语句 2016.04.18 13:16:10字数 749阅读 288 【编者按】 本文主要介绍使用系统 SQL 实体自动创建非聚集(non-clustered)索引。作者为意大利软件工程师 GhostHost(笔名)。 本文系 OneAPM 工程师编译呈现,以下为正文。 引言 一直以来,关于索引的常见问题是:判断哪部分索引对保证 数据库 的良好性能是必需的。在本文中,笔者将提供针对该问题的 解决方案 。本文用例中的所有代码都基于名为 dm_db_missing_index_details 的 SQL Server 系统视图。 背景 在开始安装前,进一步了解 dm_db_missing_index_details 会更有益处。 dm_db_missing_index_details 会返回缺失索引的细节信息。在本文中,我们将更关注以下几列: index_handle:它是一个独特的跨服务器标识符,并且标志一个特定的缺失索引。 equality_columns:包含用于相等谓词的所有列 inequality_columns:包含用于其他比较的所有列 included columns索引中所包含的查询必要出现列 statement: 补充完整索引缺失的表名 实现 本系统的实现基于以下三个实体: 一个可以计算出待创建索引名称的简单函数 一个用于简化 dm_db

探索SQL Server元数据(二)

為{幸葍}努か 提交于 2019-12-01 07:57:24
背景   上一篇中,我介绍了SQL Server 允许访问数据库的元数据,为什么有元数据,如何使用元数据。这一篇中我会介绍如何进一步找到各种有价值的信息。以触发器为例,因为它们往往一起很多问题。 那么如何找到触发器的数据?   以sys.system_views is表开始。让我们查询出数据库中使用触发器的信息。可以告知你当前SQL Server版本中有什么触发器。 SELECT schema_name(schema_ID)+'.'+ name FROM sys.system_views WHERE name LIKE '%trigger%' ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ---------------------------------------- sys.dm_exec_trigger_stats sys.server_trigger_events sys.server_triggers sys.trigger_event_types sys.trigger_events sys.triggers (6 row(s) affected)   其中sys.triggers看起来信息很多,它又包含什么列?下面这个查询很容易查到: SELECT Thecol.name+ ' '+ Type_name(TheCol

Is coalescing triggered for accessing memory in reverse order?

╄→гoц情女王★ 提交于 2019-12-01 07:13:58
问题 Let's say I have several threads and they access memory at addresses A+0, A+4, A+8, A+12 (each access = next thread). Such access is coalesced, right? However if I have access the same memory but in reverse order, meaning: thread 0 -> A+12 thread 1 -> A+8 thread 2 -> A+4 thread 3 -> A+0 Is coalescing here also triggered? 回答1: Yes, for cc 2.0 and newer GPUs, coalescing will occur for any random arrangement of 32 bit data elements to threads, as long as all the requested 32-bit data elements