myITforum.com Community Forum myITforum.com Community Forum

Home  Forums  Blogs  Live Support chat  Search Articles  Wiki  FAQ  Email Lists  Register  Login  My Profile  Inbox  Address Book  My Subscription  My Forums 

Photo Gallery  Member List  Search  Calendars  FAQ  Ticket List  Log Out

All Forums RSS Feed Subscription:


  


Unable to export results from complex query due null lines

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
  Printable Version
All Forums >> [Management Products] >> Microsoft Systems Management Server >> Web Reporting >> Unable to export results from complex query due null lines Page: [1]
Login
Message << Older Topic   Newer Topic >>
Unable to export results from complex query due null lines - 10/2/2008 12:52:29 PM   
rlauder


Posts: 82
Score: 0
Joined: 11/27/2002
From: London, England
Status: offline
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
Post #: 1
RE: Unable to export results from complex query due nul... - 10/2/2008 5:01:39 PM   
gjones


Posts: 844
Score: 50
Joined: 6/5/2001
From: Ottawa, Ontario, Canada
Status: offline
Try this..
http://smsug.ca/blogs/garth_jones/archive/2008/10/02/nocount-on.aspx


_____________________________

Garth@enhansoft.com

For a List of my Articles
http://www.myitforum.com/contrib/default.asp?cid=116
Blogs:
http://smsug.ca/blogs/garth_jones/default.aspx
http://myitforum.com/cs2/blogs/gjones/default.aspx


(in reply to rlauder)
Post #: 2
RE: Unable to export results from complex query due nul... - 10/6/2008 8:01:55 AM   
rlauder


Posts: 82
Score: 0
Joined: 11/27/2002
From: London, England
Status: offline
Garth - you are a superstar! Many thanks. That sorted it and I can now export from the web report without any problems.

(in reply to rlauder)
Post #: 3
RE: Unable to export results from complex query due nul... - 10/6/2008 11:10:07 AM  1 votes
jnelson993


Posts: 925
Score: 127
Joined: 2/18/2005
From: Minneapolis, MN
Status: offline
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




_____________________________

Number2 (John Nelson)
MyITForum - Blog
MyITForum - Forum Posts

(in reply to rlauder)
Post #: 4
RE: Unable to export results from complex query due nul... - 10/7/2008 1:09:58 PM   
rlauder


Posts: 82
Score: 0
Joined: 11/27/2002
From: London, England
Status: offline
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.

(in reply to jnelson993)
Post #: 5
Page:   [1]
All Forums >> [Management Products] >> Microsoft Systems Management Server >> Web Reporting >> Unable to export results from complex query due null lines Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts



  
Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI

0.625