isnull

C# equivalent of sql server's IsNull() function

In sql server you can use the IsNull funtion to check if a value is null. I am wondering if there is anything similar in C#, rather than manually checking: For eg: myNewValue = IsNull(myValue, new MyValue()); instead of: if (myValue == null) myValue = new MyValue(); myNewValue = myValue; Thanks. ...

LINQ ISNULL

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, Sta...

Crystal Reports formula: IsNull + Iif

There are hints of the answer to this question here and there on this site, but I'm asking a slightly different answer. Where does Crystal Reports document that this syntax does not work? Trim({PatientProfile.First}) + " " + Trim(Iif( IsNull({PatientProfile.Middle}) , Trim({PatientProfile.Middle}) + " " , "...

SQL Server Check for IsNull and for Zero

I have the following: set @SomeVariable = @AnotherVariable/isnull(@VariableEqualToZero,1) - 1 If @VariableEqualToZero is null it substitutes the 1. I need it to substitute 1 if @VariableEqualToZero = 0 as well. How do I do this? ...

ISNULL not working in TSQL Select

I have a TSQL SELECT that can return a null. I tried using ISNULL to replace it with 0 but for some reason it is not working. The table selecting from has the following columns: storeID --> int penaltyPercent --> decimal(9,2) penaltyDate --> dateTime SELECT ISNULL(penaltyPercent, 0.0) AS penaltyPercent FROM dbo.Penalty...

isNull(col, '')

How to write queries to do the followings in SubSonic/C#? select isNull(col, someDefaultValue) from table select x = case when (condition) then col1 else col2 end from table ...

SQL date type range not according to spec?

According to MSDN the range for date datatype is January 1, 1753, through December 31, 9999 In SQL2005 the following is interesting: declare @date as datetime SET @date = '1/1/1901 12:00:00 AM' SELECT @date if (isnull(@date,0) = 0) SELECT 'date is null' ELSE SELECT 'date not null' change the date to '1/1/1901 12:00:00 AM' and sudden...

Why doesn't COALESCE work with RowFilter?

Hi. I'm developing a small application in WPF. I have a ListBox named NameListBox whose ItemsSource property is set to a DataView, and thus displays a list of customer names. The name is composed of 3 parts: FirstName, MiddleName, and LastName. I have used a converter to display the full name of customer in the list. Everything works fin...

is it possible to get a class return true in is_null?

I am building some kind of a proxy pattern class for lazyloading sql queries. the proxy pattern uses __call, __get and __set for relaying calls on its object, but sometimes there is no object, if the sql did not return any rows. my question is then, if i do a is_null() on the proxy class, is it possible to make the class return true th...

How to use isnull type decision in linqdatasource orderby ?

I have a sql stored procedure that uses isnull in the order by clause to order items by the latest reply date, or if that is null, by the posting date: Example: ORDER BY isnull(rtb.LatestReplyDate,CB_TOPIC_DATE_POSTED) DESC I am trying to get that to work in the orderby clause of a linqdatasource, to no avail yet: Example: ...

isnull(email,'') = '' is NOT interpreted by it self as (email is null or email = '')?

Hi, as a fact of performance which one is better? Is there a difference between the actual 3 three versions of sql-server (2000 / 2005 / 2008)? ...

SQL - MS ACCESS - Show Cells with NULL value with 0

Hi, I tried to write a query in access. My aim is; To get results of how many surgeries are done in one day. Problem is; Result are giving me dates and how many surgeries are done but days without any surgery are not listed on the result table. I want days without surgery to be shown as 0. But there is no record about SURGERY TYPE 1...

Computed bit column that returns whether another column is null

I try to have this computed column: CREATE TABLE dbo.Item ( ItemId int NOT NULL IDENTITY (1, 1), SpecialItemId int NULL, --I tried this IsSpecialItem AS ISNULL(SpecialItemId, 0) > 0, --I tried this IsSpecialItem AS SpecialItemId IS NOT NULL --Both don't work ) ON [PRIMARY] ...

ISNULL Date month

Hi I have two dropdownlists, one with months and the other one with year. The user selects the submit month and year for the items they want to retrieve. In database the date is entered in full eg. 01/12/2009. There is an option for "All years" and "All months" in the dropdown lists but when users choose either they get null results. Ma...

Can using isnull in a where statement cause problems with using indexes?

I have a query like the following: SELECT t1.v3, t2.v2 FROM t1 INNER JOIN t2 ON t1.v1 = t2.v1 WHERE ISNULL(t1.DeleteFlag,'N') = 'N' I have an index in place that I think should result in there being an Index Seek for the = 'N' part but instead I am seeing a very expensive Index Scan. Is it possible that the index is messing up the c...

Force a value of 0 for non-existing value

Group, I am going to try and explain this as best I can, and I hope it makes (some) sense. I am pulling data from a view I have created that tells me a "Sponsor's" customer types and how many of those accounts by CustomerType are inactive after 1 year, 2 years and 3 years. For example: SponsorID | CustomerType | ExpiredAfter | Total 1...

Is this sql syntax correct?

Can i apply SUM() within an ISNULL().... Consider my following sql server select statement SELECT e.Emp_Id,e.Identity_No,e.Emp_Name,case WHEN e.SalaryBasis=1 THEN 'Weekly' ELSE 'Monthly' end as SalaryBasis,e.FixedSalary, ISNULL(Adv.Daily_Wage,0) as Advance from Employee as e inner join Designation as d on e.Desig_Id=d.Desig_Id...

ibatis problem using <isNull> whilst iterating over a List

Hi, I'm new to iBatis and I'm struggling with the and elements. I want to iterate over a List of Book instances (say) that are passed in as a HashMap: MyParameters. The list will be called listOfBooks. The clause of the overall SQL statement will therefore look like this: <iterate prepend="AND" property="MyParameters.listOfBooks" ...

DataTable.Select Behaves Strangely Using ISNULL Operator on NULL DateTime Column

I have a DataTable with a DateTime column, "DateCol", that can be DBNull. The DataTable has one row in it with a NULL value in this column. I am trying to query rows that have either DBNull value in this column or a date that is greater than today's date. Today's date is 5/11/2010. I built a query to select the rows I want, but it di...

NullDisplayText in markup vs ISNULL(field, 0) in SQL?

Which approach is better to use: BoundField.NullDisplayText isn't set. NULL-case is foreseen in SQL query, i.e. SELECT ISNULL(amount, 0) FROM table or BoundField.NullDisplayText is set, e.g. "0.00 %". NULL-case isn't foreseen in SQL query, i.e. SELECT amount FROM table What do you think? ...