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:


  


How do I convert WQL to SQL

 
Logged in as: Guest
  Printable Version
All Forums >> [Server Products] >> SQL Server >> How do I convert WQL to SQL Page: [1]
Login
Message << Older Topic   Newer Topic >>
How do I convert WQL to SQL - 1/11/2008 10:05:53 AM   
kev147

 

Posts: 84
Score: 2
Joined: 1/28/2007
Status: offline
Can someone point me in the right direction with this please?

This is what I have currently:

--Main SQL Code:
select distinct sys.Netbios_Name0,
                  sysou.System_OU_Name0,
                  sys.Operating_System_Name_and0,
                  sys.User_Name0
from              dbo.v_r_system_valid AS sys,
                  dbo.v_RA_System_SystemOUName AS sysou
where            (sysou.System_OU_Name0 LIKE @OU)

--OU Prompt SQL Code:
BEGIN
IF (@__filterwildcard = '')
SELECT DISTINCT     ou.system_ou_name0
FROM        dbo.v_ra_system_systemouname AS ou
ORDER BY ou.system_ou_name0
ELSE
SELECT DISTINCT      ou.system_ou_name0
FROM        dbo.v_ra_system_systemouname AS ou
WHERE     ou.system_ou_name0 LIKE @__filterwildcard
ORDER BY ou.system_ou_name0
END

**********************************

When I run the above report from the sccm admin console, I get this error:



Microsoft VBScript runtime
error '800a0007'
Out of memory: 'GetRows'
/SMSReporting_1PR/Report.asp, line 546

**************************************

I have the code working as an SCCM query (WQL), I just wanted to convert it to a report (SQL), this code is here:

select distinct SMS_R_System.Name,
                  SMS_R_System.OperatingSystemNameandVersion,
                  SMS_R_System.LastLogonUserName
from              SMS_R_System
where            SMS_R_System.SystemOUName = ##PRM:SMS_R_System.SystemOUName##

< Message edited by kev147 -- 1/16/2008 6:27:54 AM >
Post #: 1
RE: How do I convert WQL to SQL - 1/16/2008 6:28:38 AM   
kev147

 

Posts: 84
Score: 2
Joined: 1/28/2007
Status: offline
Polite Bump, I am sure this can be easily done. It's just that I am still a novice and need some pointers

(in reply to kev147)
Post #: 2
RE: How do I convert WQL to SQL - 1/16/2008 7:15:32 AM   
rodtrent


Posts: 1118
Score: 39
Status: offline
See if this helps...

http://www.myitforum.com/articles/18/view.asp?id=11256

(in reply to kev147)
Post #: 3
RE: How do I convert WQL to SQL - 1/16/2008 8:52:13 AM   
akaplan


Posts: 117
Score: 30
Joined: 4/22/2003
From: North Carolina
Status: offline
Or use the SQL profiler, a la Ed: http://myitforum.com/cs2/files/folders/102823/download.aspx


(in reply to kev147)
Post #: 4
RE: How do I convert WQL to SQL - 1/17/2008 10:58:28 AM   
kev147

 

Posts: 84
Score: 2
Joined: 1/28/2007
Status: offline
I tried but with no luck, to be honest I was totally confused by it all.

I did manage to get the WQL code converted to SQL and working within SQL Manager, but unable to get working within an SCCM report.

It's not imperitave that I get this working in report format anyway, it would of just been nice to have a dynamic report instead of a query.

Thanks for the pointers anyway, I may have another go at some point in the future.

Would be nice if Microsoft released a guide to do this with SCCM and SQL 2005

(in reply to akaplan)
Post #: 5
RE: How do I convert WQL to SQL - 1/27/2008 1:32:21 AM  1 votes
jnelson993


Posts: 910
Score: 145
Joined: 2/18/2005
From: Minneapolis, MN
Status: offline
quote:

ORIGINAL: kev147

Can someone point me in the right direction with this please?

This is what I have currently:

--Main SQL Code:
select distinct sys.Netbios_Name0,
                 sysou.System_OU_Name0,
                 sys.Operating_System_Name_and0,
                 sys.User_Name0
from              dbo.v_r_system_valid AS sys,
                 dbo.v_RA_System_SystemOUName AS sysou
where            (sysou.System_OU_Name0 LIKE @OU)
**********************************
When I run the above report from the sccm admin console, I get this error:

Microsoft VBScript runtime
error '800a0007'
Out of memory: 'GetRows'
/SMSReporting_1PR/Report.asp, line 546
**************************************

I have the code working as an SCCM query (WQL), I just wanted to convert it to a report (SQL), this code is here:


I'm sorry, I don't know how I missed this post, I certainly would have responded right away if I would have seen it.

Anyway, you have a cartesian/cross join (every row in the first table/view joins to every row in the second table/view)  This could create billions of rows of output and overwhelm your IIS server and give you the out of memory error.  SQL Management Studio can handle that kind of output which is why it works there for you, but IIS can't handle that bulk out of the box.

quote:


from              dbo.v_r_system_valid AS sys,
                 dbo.v_RA_System_SystemOUName AS sysou
where            (sysou.System_OU_Name0 LIKE @OU)

See, you're selecting everything from SYS and everything from SYSOU, but you've got no JOIN statement.  If the two views have 10,000 rows, the cartesian/cross join would produce 100Million rows.  And it goes up exponentially the more rows you have in each table.

So, that little bit should be rewritten like this:
from              dbo.v_r_system_valid AS sys
                 INNER JOIN dbo.v_RA_System_SystemOUName AS sysou

                     ON sys.ResourceID = sysou.ResourceID
where            (sysou.System_OU_Name0 LIKE @OU)

 
Although, there's one more thing missing, for every machine that's in an OU, it's a member of every link up the chain.  So if a machine is assigned to the OU:
CORP.DOMAIN\TOP\LEVEL1\LEVEL2\LEVEL3
it will also have an OU record for
CORP.COMAIN\TOP\LEVEL1\LEVEL2
CORP.COMAIN\TOP\LEVEL1
CORP.COMAIN\TOP
CORP.COMAIN
It'll return 5 records for that one machine.  So you'll probably want to use a GROUP BY and a MAX in your SQL in order to get the full OU for a machine and skip all of those intermediate levels.  Sooo, I'd rewrite your whole query like this:
  SELECT sys.Netbios_Name0              as [Computer Name],
        MAX(sysou.System_OU_Name0)     as [Full OU],
        sys.Operating_System_Name_and0 as OS,
        sys.User_Name0                 as [User Name]
   FROM dbo.v_r_system_valid AS sys
        INNER JOIN dbo.v_RA_System_SystemOUName AS sysou
           ON sys.ResourceID = sysou.ResourceID
  WHERE sysou.System_OU_Name0 LIKE @OU
GROUP BY sys.Netbios_Name0,
        sys.Operating_System_Name_and0,
        sys.User_Name0


I don't have SCCM operating yet so I haven't run this myself, but I've done enough of these by hand and it's close enough to SMS so I'm pretty confident this is good code.
SOME THINGS TO NOTE ABOUT THIS QUERY:  there's an INNER JOIN statement that your query was missing and the GROUP BY removes duplicates at the same time it aggregates the rows together so the DISTINCT isn't needed. 

I hope this helps.

_____________________________

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

(in reply to kev147)
Post #: 6
RE: How do I convert WQL to SQL - 1/28/2008 5:11:15 AM   
kev147

 

Posts: 84
Score: 2
Joined: 1/28/2007
Status: offline
Thanks John that worked a treat.

Thanks for the explanation as well. I am complete novice when it comes to SQL, I have it on my list of things to improve my knowledge on.

I know it is something you are probably always learning new things, but can I ask how long it took you to get to where you are now with SQL?

(in reply to jnelson993)
Post #: 7
RE: How do I convert WQL to SQL - 1/28/2008 12:19:01 PM   
jnelson993


Posts: 910
Score: 145
Joined: 2/18/2005
From: Minneapolis, MN
Status: offline
The first time I wrote (tried to write) a query was around SMS 1.2, just before SMS 2.0 beta came out...but I haven't done full-time SQL type stuff the whole time.  So I'd say if you were working full-time at SQL type things, a person could probably be where I am in 3-4 years if you have a programming/scripting background.

_____________________________

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

(in reply to kev147)
Post #: 8
RE: How do I convert WQL to SQL - 9/9/2008 5:18:51 AM   
Tom_Watson

 

Posts: 161
Score: 18
Joined: 9/13/2006
Status: offline
Additional to what John has written, you can get a feel for how SMS converts WQL to SQL in these articles :-

http://myitforum.com/cs2/blogs/bleary/archive/tags/SQL+Basics+for+SMS+Admins/default.aspx

I started off with stuff like this, but after a while I've gotten to the stage where I can write basic reports directly in SQL using SQL Query Analyser or Management Studio.

Regards,
Tom Watson

(in reply to jnelson993)
Post #: 9
Page:   [1]
All Forums >> [Server Products] >> SQL Server >> How do I convert WQL to SQL 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.906