Groups | Blog | Home
all groups > sql server new users > august 2006 >

sql server new users : Converting NULL to something else when data is queried


Jim in Arizona
8/18/2006 9:55:05 AM
I'm working on an ASP.NET project and when a query is ran, some rows
returned are NULL, which is causing my app to break. The data is pulled
into my webpage as a string, which I'm converting to Int32 to do a
number comparison for page formatting purposes. If the value is NULL,
then the NULL value cannot be converted to Int32, which causes the app
to break.

Here is the SQL statement that is being ran:
==================================================
SELECT
m.[Client ID]
,CONVERT(varchar(10),t.[Date],101) AS [Date]
,Putime = convert(varchar(8), t.Putime, 108)
,Apptime = convert(varchar(8), t.Apptime, 108)
,Dotime = convert(varchar(8), t.Dotime, 108)
,Rputime = convert(varchar(8), t.Rputime, 108)
,Rdotime = convert(varchar(8), t.Rdotime, 108)
,Apptimeout = convert(varchar(8), t.Apptimeout, 108)
,datediff(minute, t.Putime, t.Apptime) AS 'PU to Appt'
,datediff(minute, t.Dotime, t.Apptime) AS 'DO to Appt'
,datediff(minute, t.Apptimeout, t.Rputime) as 'Appt to RPU'
,datediff(minute, t.Apptimeout, t.Rdotime) as 'Appt to RDO'
FROM [T-Client Master] m
INNER JOIN [T-CMDB] t
ON m.[Client ID] = t.[Client ID]
WHERE t.Date = convert(datetime, @dt, 101)
==================================================

The datediff are the the ones that are returning NULL values among the
non null values. Is there a way to convert any NULL values into in blank
string (ie. '') or 0 Integer or something other than null?

The specific ones I need to place non null values in are:

,datediff(minute, t.Dotime, t.Apptime) AS 'DO to Appt'
,datediff(minute, t.Apptimeout, t.Rputime) as 'Appt to RPU'

TIA,
Barry
8/18/2006 10:13:37 AM
Jim,

You need to use the IsNull() Function.

e.g

Select IsNull(ClientName, 'No Client Name') As 'ClientName'

[quoted text, click to view]

HTH

Barry


[quoted text, click to view]
Jim in Arizona
8/18/2006 10:22:38 AM
[quoted text, click to view]


I don't know how I would implement that in the SELECT statement above.
Could you please show me how?

Arnie Rowland
8/18/2006 11:19:36 AM
[quoted text, click to view]
RPU'


--=20
Arnie Rowland, Ph.D.
Westwood Consulting, Inc

Most good judgment comes from experience.=20
Most experience comes from bad judgment.=20
- Anonymous


[quoted text, click to view]
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=

[quoted text, click to view]
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=

[quoted text, click to view]
Jim in Arizona
8/18/2006 12:17:41 PM
[quoted text, click to view]

Arnie Rowland
8/18/2006 12:31:59 PM
Glad to be of help Jim.

As you progress in your skills, remember, there is always someone else that
might benefit from what you already know. So please stop by these newsgroups
and help out when you can.

--
Arnie Rowland, Ph.D.
Westwood Consulting, Inc

Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous


[quoted text, click to view]

AddThis Social Bookmark Button