3 Replies - 733 Views - Last Post: 08 June 2012 - 05:43 PM Rate Topic: -----

#1 RainbowInTheDark  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 05-June 12

ISNULL FUNCTION

Posted 08 June 2012 - 10:12 AM

I'm trying to retrieve data from MS SQL with a table(DemeritPoints):

SELECT Stu_TypesofOffence, Stu_DatenTime,Stu_RepetitionOffence,Stu_OffenceDetails,Stu_LocationOffence,Stu_InitialAction,Stu_ConWarn,Stu_Comments,Stu_DemeritPoints, ISNULL(150 - Stu_DemeritPoints,150) AS Expr1 From DemeritPoints WHERE Stu_Class=@Stu_Class



THe problem is that the code for this is not displaying in the detailsView control.
What is wrong with this ??

This post has been edited by modi123_1: 08 June 2012 - 10:34 AM
Reason for edit:: highlight the lines THEN click the code tags button in the 'format text' box of the post.


Is This A Good Question/Topic? 0
  • +

Replies To: ISNULL FUNCTION

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8937
  • View blog
  • Posts: 33,462
  • Joined: 12-June 08

Re: ISNULL FUNCTION

Posted 08 June 2012 - 10:38 AM

Explain what you mean by "not displaying in the detailsView control.".

ISNULL(150 - Stu_DemeritPoints,150)

Why are you doing an 'isnull' around a math function? in MSSQL a number minus a null is a null.... so it might better to evaluate the column itself as null and not the math operation.. Just say'n.. it makes more sense.
Was This Post Helpful? 0
  • +
  • -

#3 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5777
  • View blog
  • Posts: 12,591
  • Joined: 16-October 07

Re: ISNULL FUNCTION

Posted 08 June 2012 - 10:41 AM

Perhaps you wanted:
150 - IsNull(Stu_DemeritPoints,0) AS Expr1


Was This Post Helpful? 0
  • +
  • -

#4 e_i_pi  Icon User is offline

  • = -1
  • member icon

Reputation: 789
  • View blog
  • Posts: 1,676
  • Joined: 30-January 09

Re: ISNULL FUNCTION

Posted 08 June 2012 - 05:43 PM

I would imagine ISNULL would still work under the OPs code, since 150 - NULL evaluates to NULL (I believe - haven't got my MSSQL kit in front of me).

Have you tried running something like this in SSMS:
DECLARE @Stu_Class AS int;
SET @Stu_Class = 1;
SELECT
	Stu_TypesofOffence,
	Stu_DatenTime,
	Stu_RepetitionOffence,
	Stu_OffenceDetails,
	Stu_LocationOffence,
	Stu_InitialAction,
	Stu_ConWarn,
	Stu_Comments,
	Stu_DemeritPoints,
	ISNULL(150 - Stu_DemeritPoints,150) AS Expr1
From DemeritPoints
WHERE Stu_Class=@Stu_Class


I am assuming, of course, that DemeritPoints.STU_Class is of datatype int, and that WHERE Stu_Class = 1 would return at least one result. If you can get that returning results, then the problem may be in your display code, or the parameters you are passing.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1