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,
Jim, You need to use the IsNull() Function. e.g Select IsNull(ClientName, 'No Client Name') As 'ClientName' [quoted text, click to view] >From Clients
HTH Barry [quoted text, click to view] Jim in Arizona wrote: > 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, > Jim
[quoted text, click to view] Barry wrote: > Jim, > > You need to use the IsNull() Function. > > e.g > > Select IsNull(ClientName, 'No Client Name') As 'ClientName' > >>From Clients > > HTH > > Barry > > > Jim in Arizona wrote: >> 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)
I don't know how I would implement that in the SELECT statement above. Could you please show me how?
[quoted text, click to view] > , isnull( datediff(minute, t.Dotime, t.Apptime), 0 ) AS 'DO to = Appt' > , isnull( datediff(minute, t.Apptimeout, t.Rputime), 0 ) AS 'Appt to =
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] "Jim in Arizona" <tiltowait@hotmail.com> wrote in message = news:eeUo5ZuwGHA.1888@TK2MSFTNGP03.phx.gbl... > I'm working on an ASP.NET project and when a query is ran, some rows=20 > returned are NULL, which is causing my app to break. The data is = pulled=20 > into my webpage as a string, which I'm converting to Int32 to do a=20 > number comparison for page formatting purposes. If the value is NULL,=20 > then the NULL value cannot be converted to Int32, which causes the app = > to break. >=20 > Here is the SQL statement that is being ran: > =
=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] > SELECT > m.[Client ID] > ,CONVERT(varchar(10),t.[Date],101) AS [Date] > ,Putime =3D convert(varchar(8), t.Putime, 108) > ,Apptime =3D convert(varchar(8), t.Apptime, 108) > ,Dotime =3D convert(varchar(8), t.Dotime, 108) > ,Rputime =3D convert(varchar(8), t.Rputime, 108) > ,Rdotime =3D convert(varchar(8), t.Rdotime, 108) > ,Apptimeout =3D 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] =3D t.[Client ID] > WHERE t.Date =3D convert(datetime, @dt, 101) > =
=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] >=20 > 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=20 > string (ie. '') or 0 Integer or something other than null? >=20 > The specific ones I need to place non null values in are: >=20 > ,datediff(minute, t.Dotime, t.Apptime) AS 'DO to Appt' > ,datediff(minute, t.Apptimeout, t.Rputime) as 'Appt to RPU' >=20 > TIA,
[quoted text, click to view] Arnie Rowland wrote: > > , isnull( datediff(minute, t.Dotime, t.Apptime), 0 ) AS 'DO to > Appt' > > , isnull( datediff(minute, t.Apptimeout, t.Rputime), 0 ) AS 'Appt to RPU' > > -- > Arnie Rowland, Ph.D. > Westwood Consulting, Inc > > Most good judgment comes from experience. > Most experience comes from bad judgment. > - Anonymous >
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] "Jim in Arizona" <tiltowait@hotmail.com> wrote in message news:uV7rkpvwGHA.2260@TK2MSFTNGP03.phx.gbl... > Arnie Rowland wrote: >> > , isnull( datediff(minute, t.Dotime, t.Apptime), 0 ) AS 'DO to >> Appt' >> > , isnull( datediff(minute, t.Apptimeout, t.Rputime), 0 ) AS 'Appt to >> RPU' >> >> -- >> Arnie Rowland, Ph.D. >> Westwood Consulting, Inc >> Most good judgment comes from experience. >> Most experience comes from bad judgment. >> - Anonymous >> > > Thanks again Dr. Rowland.
Don't see what you're looking for? Try a search.
|