isnull

CASTing a datetime to string if null value - keeping original datetime formatting

故事扮演 提交于 2020-01-17 07:03:31
问题 I have the following part of my query: ISNULL(cast(fd.decision_date as varchar(20)), 'PENDING') as facility, ISNULL(cast(cd.decision_date as varchar(20)), 'PENDING') as corporate, ISNULL(cast(cb.creation_date as varchar(20)), 'PENDING') as billing My values are originally of datetime datatype, but what I want to do is return the word 'PENDING' if the value is NULL. With the code above, my results are cast ed to a varchar , thus returning something like: Aug 20 2013 9:35AM instead of 2013-08

Entity Framework ISNULL in Where condition

落爺英雄遲暮 提交于 2020-01-14 10:27:06
问题 I have a Query in SQL Server : SELECT * FROM MyTable t WHERE ISNULL(t.Status,'') = '' How I can do it in Entity Framework? EDIT: Oh Sorry my code was like WHERE ISNULL(t.Status,'') = '' 回答1: Try something like MyTable.Where( t => (t.Status ?? "") == "CO" ) 回答2: Although the question is ok, the logic isn't sound. Because if a value is equal to CO , it can never be equal to either NULL or '' . In this case you could just easily call it like this: SQL: SELECT * FROM MyTable t WHERE t.Status =

Checking MySQL NULL values with PHP

非 Y 不嫁゛ 提交于 2020-01-04 06:35:29
问题 This is how my table looks like.. id col1 col2 --------------- 1 a x 2 NULL y 3 NULL z 4 NULL t col1 has a default value of NULL . I want to use col1 data If col1 is not null, otherwise use col2 data. function something($col1,$col2) { if(is_null($col1) == true) $var = $col2 else $var = $col1 return $var; } function something2($col1,$col2) { if($col1 === NULL) $var = $col2 else $var = $col1 return $var; } Here is my problem. Both of these functions returns $col2 values. But as you can see in

Checking MySQL NULL values with PHP

心不动则不痛 提交于 2020-01-04 06:34:28
问题 This is how my table looks like.. id col1 col2 --------------- 1 a x 2 NULL y 3 NULL z 4 NULL t col1 has a default value of NULL . I want to use col1 data If col1 is not null, otherwise use col2 data. function something($col1,$col2) { if(is_null($col1) == true) $var = $col2 else $var = $col1 return $var; } function something2($col1,$col2) { if($col1 === NULL) $var = $col2 else $var = $col1 return $var; } Here is my problem. Both of these functions returns $col2 values. But as you can see in

Why IsNull is twice slow as coalesce (same query)?

老子叫甜甜 提交于 2020-01-01 03:33:28
问题 We met a strange situation on SQL Server 2008 (SP1) - 10.0.2531.0 (X64) - Win2008 SP2 (X64). Here is a one heavy query: select t1.id, t2.id from t1, t2 where t1.id = t2.ext_id and isnull(t1.vchCol1, 'Null') = isnull(t2.vchCol1, 'Null') and isnull(t1.vchCol2, 'Null') = isnull(t2.vchCol2, 'Null') .... and about 10 more comparisons with Isnull UPD : All columns in comparison (except IDs) are varchar (~30...200) T1 is ~130mln rows, T2 is ~300k rows. These query on rather big Dev server run ~5

Expressing “is null” in Relational algebra

北战南征 提交于 2019-12-29 09:25:10
问题 In SQL, if I want to know whether an expression is NULL, I can use is null . But I don't understand how I can express is null in relational algebra. Can I use δ Field_Name=NULL(Table_Name) ? 回答1: There is no NULL in relational algebra. In SQL the operators treat the value NULL specially, syntactically and semantically, differently than other values, usually by returning NULL when comparing two values when one of them is NULL. So "=" in a WHERE is not equality, it is an operator like equality

Equivalent of SQL ISNULL in LINQ?

…衆ロ難τιáo~ 提交于 2019-12-27 11:45:44
问题 In SQL you can run a ISNULL(null,'') how would you do this in a linq query? I have a join in this query: var hht = from x in db.HandheldAssets join a in db.HandheldDevInfos on x.AssetID equals a.DevName into DevInfo from aa in DevInfo.DefaultIfEmpty() select new { AssetID = x.AssetID, Status = xx.Online }; but I have a column that has a bit type that is non nullable (xx.online) how can I set this to false if it is null? 回答1: Since aa is the set/object that might be null, can you check aa ==

Using ISNULL vs using COALESCE for checking a specific condition?

牧云@^-^@ 提交于 2019-12-27 11:07:06
问题 I know that multiple parameters can be passed to COALESCE , but when you want to to check just one expression to see if it doesn't exist, do you use a default or is it a better practice to use ISNULL instead? Is there any performance gain between the two? 回答1: This problem reported on Microsoft Connect reveals some differences between COALESCE and ISNULL : an early part of our processing rewrites COALESCE( expression1, expression2 ) as CASE WHEN expression1 IS NOT NULL THEN expression1 ELSE

Using ISNULL vs using COALESCE for checking a specific condition?

末鹿安然 提交于 2019-12-27 11:06:20
问题 I know that multiple parameters can be passed to COALESCE , but when you want to to check just one expression to see if it doesn't exist, do you use a default or is it a better practice to use ISNULL instead? Is there any performance gain between the two? 回答1: This problem reported on Microsoft Connect reveals some differences between COALESCE and ISNULL : an early part of our processing rewrites COALESCE( expression1, expression2 ) as CASE WHEN expression1 IS NOT NULL THEN expression1 ELSE

Using ISNULL vs using COALESCE for checking a specific condition?

故事扮演 提交于 2019-12-27 11:06:11
问题 I know that multiple parameters can be passed to COALESCE , but when you want to to check just one expression to see if it doesn't exist, do you use a default or is it a better practice to use ISNULL instead? Is there any performance gain between the two? 回答1: This problem reported on Microsoft Connect reveals some differences between COALESCE and ISNULL : an early part of our processing rewrites COALESCE( expression1, expression2 ) as CASE WHEN expression1 IS NOT NULL THEN expression1 ELSE