How do I convert WQL to SQL (Full Version)

All Forums >> [Server Products] >> SQL Server



Message


kev147 -> How do I convert WQL to SQL (1/11/2008 10:05:53 AM)

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##




kev147 -> RE: How do I convert WQL to SQL (1/16/2008 6:28:38 AM)

Polite Bump, I am sure this can be easily done. It's just that I am still a novice and need some pointers




rodtrent -> RE: How do I convert WQL to SQL (1/16/2008 7:15:32 AM)

See if this helps...

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




akaplan -> RE: How do I convert WQL to SQL (1/16/2008 8:52:13 AM)

Or use the SQL profiler, a la Ed: http://myitforum.com/cs2/files/folders/102823/download.aspx





kev147 -> RE: How do I convert WQL to SQL (1/17/2008 10:58:28 AM)

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




jnelson993 -> RE: How do I convert WQL to SQL (1/27/2008 1:32:21 AM)

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.




kev147 -> RE: How do I convert WQL to SQL (1/28/2008 5:11:15 AM)

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?




jnelson993 -> RE: How do I convert WQL to SQL (1/28/2008 12:19:01 PM)

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.




Tom_Watson -> RE: How do I convert WQL to SQL (9/9/2008 5:18:51 AM)

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




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.65625