isnull

C# equivalent of the IsNull() function in SQL Server

女生的网名这么多〃 提交于 2019-12-02 14:59:45
In SQL Server you can use the IsNull() function to check if a value is null, and if it is, return another value. Now I am wondering if there is anything similar in C#. For example, I want to do something like: myNewValue = IsNull(myValue, new MyValue()); instead of: if (myValue == null) myValue = new MyValue(); myNewValue = myValue; Thanks. Kent Boogaart It's called the null coalescing ( ?? ) operator: myNewValue = myValue ?? new MyValue(); Sadly, there's no equivalent to the null coalescing operator that works with DBNull; for that, you need to use the ternary operator: newValue = (oldValue

Keyboard shortcut to automatically wrap selected text in IsNull([text], 0) in SSMS

China☆狼群 提交于 2019-12-02 13:13:35
问题 Is there some way to have a shortcut in SQL Server Management Studio (SSMS) that when text is selected, it wraps that text in an IsNull() statement? For example, I highlight the text below: My_column_name and when I click the keyboard shortcut, what was highlighted turns into: IsNull(My_column_name, 0) I am using SSMS v17.4 回答1: You can get this done using snippets. It's not exactly a simple shortcut, but a few keystrokes will get you there. First you need to create a snippet like this: <?xml

Include null results in group_concat

隐身守侯 提交于 2019-12-02 06:49:48
I have two tables like this profile_answers +---------+------------+ | id | class_name | +---------+------------+ | 1 | Class 1 | | 2 | Class 2 | | 3 | Class 1 | +---------+------------+ educations +---------+--------------------+------------+ | id | profile_answers_id | sample | +---------+--------------------+------------+ | 1 | 1 | 1234 | | 2 | 1 | 2334 | | 3 | 1 | 3434 | +---------+------------+--------------------+ I ran the query, select educations.profile_answer_id, GROUP_CONCAT(educations.sample) from educations LEFT JOIN profile_answers ON educations.profile_answers_id = profile

Keyboard shortcut to automatically wrap selected text in IsNull([text], 0) in SSMS

泄露秘密 提交于 2019-12-02 04:21:13
Is there some way to have a shortcut in SQL Server Management Studio (SSMS) that when text is selected, it wraps that text in an IsNull() statement? For example, I highlight the text below: My_column_name and when I click the keyboard shortcut, what was highlighted turns into: IsNull(My_column_name, 0) I am using SSMS v17.4 You can get this done using snippets. It's not exactly a simple shortcut, but a few keystrokes will get you there. First you need to create a snippet like this: <?xml version="1.0" encoding="utf-8" ?> <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005

What's the meaning of the reverse entry (null === $value) when checking the value of the variable? [duplicate]

随声附和 提交于 2019-12-01 20:52:24
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: PHP - reversed order in if statement Checking for null - what order? Examining Zend Framework found that they do all the variable checkings reverse way: public function setBootstrap($path, $class = null) { if (null === $class) { // instead of if($class === null) $class = 'Bootstrap'; } What's the reason of doing this? Is this also suitable for Java and C++ programming? 回答1: some people believe it helps them in

What's the meaning of the reverse entry (null === $value) when checking the value of the variable? [duplicate]

好久不见. 提交于 2019-12-01 18:31:58
Possible Duplicate: PHP - reversed order in if statement Checking for null - what order? Examining Zend Framework found that they do all the variable checkings reverse way: public function setBootstrap($path, $class = null) { if (null === $class) { // instead of if($class === null) $class = 'Bootstrap'; } What's the reason of doing this? Is this also suitable for Java and C++ programming? some people believe it helps them in avoiding to write a single = (an assignment instead of a comparison for equality) I believe that the advantage of doing so is much less than the loss of readability (and

How does Left Join / IS NULL eliminate records which are there in one table and not in the other?

霸气de小男生 提交于 2019-11-30 22:35:31
I am having a tough time to understand why does LEFT JOIN / IS NULL eliminate records which are there in one table and not in the other. Here is an example SELECT l.id, l.value FROM t_left l LEFT JOIN t_right r ON r.value = l.value WHERE r.value IS NULL Why should r.value = NULL eliminate records ? I am not understanding . I know I am missing something very basic but at present I cant figure out even that basic one. I would appreciate if someone explains it to me in detail . I want a very basic explanation. This could be explained with the following mysql> select * from table1 ; +------+------

Finding null value in Dataset - DataRow.IsNull method vs ==DbNull.Value - c#

与世无争的帅哥 提交于 2019-11-30 18:02:27
What are the benefits of using the c# method DataRow.IsNull to determine a null value over checking if the row equals DbNull.value? if(ds.Tables[0].Rows[0].IsNull("ROWNAME")) {do stuff} vs if(ds.Tables[0].Rows[0]["ROWNAME"] == DbNull.value) {do stuff} There is no real practical benefit. Use whichever one seems more readable to you. As to the particular differences between them, the basic answer is that IsNull queries the null state for a particular record within a column. Using == DBNull.Value actually retrieves the value and does substitution in the case that it's actually null. In other

How does Left Join / IS NULL eliminate records which are there in one table and not in the other?

怎甘沉沦 提交于 2019-11-30 17:20:05
问题 I am having a tough time to understand why does LEFT JOIN / IS NULL eliminate records which are there in one table and not in the other. Here is an example SELECT l.id, l.value FROM t_left l LEFT JOIN t_right r ON r.value = l.value WHERE r.value IS NULL Why should r.value = NULL eliminate records ? I am not understanding . I know I am missing something very basic but at present I cant figure out even that basic one. I would appreciate if someone explains it to me in detail . I want a very

Is there a opposite function to ISNULL in sql server? To do Is not null?

南楼画角 提交于 2019-11-30 10:48:24
I have this code in my select statement ISNULL(a.PolicySignedDateTime,aq.Amount) AS 'Signed Premium', But I want to see if "a.PolicySignedDateTime" is not null. Is there a easy function to do this which does not involve using a "if" statement? Cheers guys You have to use CASE SELECT CASE WHEN Field IS NOT NULL THEN 'something' ELSE 'something else' END There is the COALESCE expression (although not function https://msdn.microsoft.com/en-us/library/ms190349.aspx ) test the arguments in order and keep doing it until finds the value not NULL and returns it. example usage: SELECT COALESCE(NULL,