Unable to export results from complex query due null lines (Full Version)

All Forums >> [Management Products] >> Microsoft Systems Management Server >> Web Reporting



Message


rlauder -> Unable to export results from complex query due null lines (10/2/2008 12:52:29 PM)

If anyone can help me with this, I'd be very pleased indeed!

I have a monster query that we use to show current disk and cpu info for our community of laptops. In order to show C & D drive info (and CPU1 & CPU2 info) as separate columns, I've had to resort to creating temporary tables to store the intermediate results.

If I run it in SQL Query Analyser it works a treat. It actually runs fine through the SMS web browser but the "INSERT INTO " entries cause blank, "no records found" lines to come up on the browser before the meaty report with all the laptop data in it.

As a result of these "null" lines, the export function doesn't work. I guess it looks at the first piece of data, sees nothing and decides that there's nothing to export.

Does anyone know how I can get the web report to run without displaying lines associated with the INSERT commands so that I can export the main report?

Here's the SQL ==>

CREATE TABLE #CDisk (resourceid varchar(64), size0 varchar(64), freespace0 varchar(64))
CREATE TABLE #DDisk (resourceid varchar(64), size0 varchar(64), freespace0 varchar(64))
CREATE TABLE #CPU1 (resourceid varchar(64), currentclockspeed0 int, maxclockspeed0 int)
CREATE TABLE #CPU2 (resourceid varchar(64), currentclockspeed0 int, maxclockspeed0 int)

INSERT INTO #CDisk
select  distinct vrs.resourceid, dsk.size0, dsk.freespace0
from v_R_system vrs inner join v_gs_logical_disk dsk on vrs.resourceid = dsk.resourceid
where dsk.name0 = 'C:'
INSERT INTO #DDisk
select  distinct vrs.resourceid, dsk.size0, dsk.freespace0
from v_R_system vrs inner join v_gs_logical_disk dsk on vrs.resourceid = dsk.resourceid
where dsk.name0 = 'D:'
INSERT INTO #CPU1
select vrs.resourceid, cpu.currentclockspeed0, cpu.maxclockspeed0
from v_R_system vrs inner join v_GS_Processor cpu on vrs.resourceid = cpu.resourceid
where cpu.deviceid0 = 'CPU0'
INSERT INTO #CPU2
select  vrs.resourceid, cpu.currentclockspeed0, cpu.maxclockspeed0
from v_R_system vrs inner join v_GS_Processor cpu on vrs.resourceid = cpu.resourceid
where cpu.deviceid0 = 'CPU1'

select distinct VRS.Name0, ws.LastHWScan, VRS.User_Name0, CS.Model0,
cp1.currentclockspeed0 as "Current Speed CPU1/MHz", cp1.maxclockspeed0 as "Max Speed CPU1/MHz",
cp2.currentclockspeed0 as "Current Speed CPU2/MHz", cp2.maxclockspeed0 as "Max Speed CPU2/MHz",
mem.totalphysicalmemory0 as "Total RAM",
ds1.size0 as "C: Total/MB", ds1.freespace0 as "C: Free/MB",
ds2.size0 as "D: Total/MB", ds2.freespace0 as "D: Free/MB"
from v_R_System VRS INNER JOIN v_GS_COMPUTER_SYSTEM CS on vrs.resourceid = cs.resourceid
inner join v_GS_SYSTEM_ENCLOSURE senc on vrs.resourceid = senc.resourceid
inner join v_GS_WORKSTATION_STATUS ws on vrs.resourceid = ws.resourceid
left join #CPU1 cp1 on vrs.resourceid = cp1.resourceid
left join #CPU2 cp2 on vrs.resourceid = cp2.resourceid
inner join v_GS_X86_PC_Memory mem on vrs.resourceid = mem.resourceid
inner join #CDisk ds1 on vrs.resourceid = ds1.resourceid
left join #DDisk ds2 on vrs.resourceid = ds2.resourceid
where senc.ChassisTypes0 in (8,9,10,12,14,21)
order by VRS.Name0

drop table #CDisk
drop table #DDisk
drop table #CPU1
drop table #CPU2




gjones -> RE: Unable to export results from complex query due null lines (10/2/2008 5:01:39 PM)

Try this..
http://smsug.ca/blogs/garth_jones/archive/2008/10/02/nocount-on.aspx




rlauder -> RE: Unable to export results from complex query due null lines (10/6/2008 8:01:55 AM)

Garth - you are a superstar! Many thanks. That sorted it and I can now export from the web report without any problems.




jnelson993 -> RE: Unable to export results from complex query due null lines (10/6/2008 11:10:07 AM)

rlauder,
I hope you don't mind my input...everything you're doing can be done in one query by using a GROUP BY and MAX(CASE...)

SELECT
  VRS.Name0,
  ws.LastHWScan,
  VRS.User_Name0,
  CS.Model0,
  MAX(CASE WHEN cpu.deviceID0 = 'CPU0' THEN cpu.currentclockspeed0 END)  AS "Current Speed CPU1/MHz",
  MAX(CASE WHEN cpu.deviceID0 = 'CPU0' THEN cpu.maxclockspeed0 END)      AS "Max Speed CPU1/MHz",
  MAX(CASE WHEN cpu.deviceID0 = 'CPU1' THEN cpu.currentclockspeed0 END)  AS "Current Speed CPU2/MHz",
  MAX(CASE WHEN cpu.deviceID0 = 'CPU1' THEN cpu.maxclockspeed0 END)      AS "Max Speed CPU2/MHz",
  mem.totalphysicalmemory0 AS "Total RAM",
  MAX(CASE WHEN dsk.name0 = 'C:' THEN dsk.size0 END)         AS "C: Total/MB",
  MAX(CASE WHEN dsk.name0 = 'C:' THEN dsk.freespace0 END)    AS "C: Free/MB",
  MAX(CASE WHEN dsk.name0 = 'D:' THEN dsk.size0 END)         AS "D: Total/MB",
  MAX(CASE WHEN dsk.name0 = 'D:' THEN dsk.freespace0 END)    AS "D: Free/MB"
FROM    
  v_R_System VRS
  INNER JOIN v_GS_COMPUTER_SYSTEM CS
    ON vrs.resourceid = cs.resourceid
  INNER JOIN v_GS_SYSTEM_ENCLOSURE senc
    ON vrs.resourceid = senc.resourceid
   AND senc.ChassisTypes0 IN (8,9,10,12,14,21)
  INNER JOIN v_GS_WORKSTATION_STATUS ws
    ON vrs.resourceid = ws.resourceid
  LEFT JOIN v_GS_Processor cpu
    ON vrs.resourceid = cpu.resourceid
  INNER JOIN v_GS_X86_PC_Memory mem
    ON vrs.resourceid = mem.resourceid
  INNER JOIN v_GS_Logical_Disk dsk
    ON vrs.resourceid = dsk.resourceid
GROUP BY
  VRS.Name0,
  ws.LastHWScan,
  VRS.User_Name0,
  CS.Model0,
  mem.totalphysicalmemory0

ORDER BY VRS.Name0






rlauder -> RE: Unable to export results from complex query due null lines (10/7/2008 1:09:58 PM)

Wow - nice one John! As always, there seem to be many ways to skin the cat. Clearly yours is much easier (and less bloody!) than mine.

Once again, the myitforum community shows how powerful it is. Many thanks.




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.171875