domingo, fevereiro 23, 2014

How to get an TOP 10 for SQL in Oracle

 
You'll need to put your current query in subquery as below :

SELECT * FROM (
  SELECT DISTINCT 
  APP_ID, 
  NAME, 
  STORAGE_GB, 
  HISTORY_CREATED, 
  TO_CHAR(HISTORY_DATE, 'DD.MM.YYYY') AS HISTORY_DATE  
  FROM HISTORY WHERE 
    STORAGE_GB IS NOT NULL AND 
      APP_ID NOT IN (SELECT APP_ID FROM HISTORY WHERE TO_CHAR(HISTORY_DATE, 'DD.MM.YYYY') ='06.02.2009')
  ORDER BY STORAGE_GB DESC )
WHERE ROWNUM <= 10
 
Oracle applies rownum to the result after it has been returned.
You need to filter the result after it has been returned, so a subquery is required. You can also use RANK() function to get Top-N results.

For performance try using NOT EXISTS in place of NOT IN.


quinta-feira, janeiro 02, 2014

Learn to narrow your search criteria for better searches in Outlook

Lista de metodos para fazer searchs mais fáceis no Outlook.
Link original em:

http://office.microsoft.com/en-001/outlook-help/learn-to-narrow-your-search-criteria-for-better-searches-in-outlook-HA010238831.aspx


The following table shows examples of searches you might find useful. The search query syntax, available when the Instant Search (Instant Search: A Search feature that provides search results quickly with word highlighting as you type. The Instant Search pane is always available in Mail, Calendar, Contacts, Tasks, Notes, Folder List, and Journal.) feature is enabled, follows this basic form: keyword:your search criteria value.
For example, from:bobby
You can also use logical operators AND, NOT, OR, <, >, =, and so forth to refine your search, and these are noted in the table. Logical operators must be typed in uppercase letters.
Note The search query syntax is created automatically and displayed in the Instant Search box when you use the Query Builder described in the previous section.

Type this To find this
bobby Items containing bobby, BOBBY, BoBby, or any other combination of uppercase and lowercase letters. Instant Search is not case sensitive.
bobby moore Items containing both bobby and moore, but not necessarily in that order.
bobby AND mooreItems containing both bobby and moore, but not necessarily in that order. Note that logical operators such as AND, NOT, and OR must be in uppercase letters.
bobby NOT moore Items containing bobby, but not moore.
bobby OR moore Items containing bobby, moore, or both.
"bobby moore" Items containing the exact phrase bobby moore. Note the use of double quotes so that the search results match the exact phrase within the quotes.
from:"bobby moore" Items sent from bobby moore. Note the use of double quotes so that the search results match the exact phrase within the quotes.
from:"bobby moore" about:”status report”Items sent from bobby moore where status report appears in the subject line, body, and attachment contents. Note the use of double quotes so that the search results match the exact phrase within the quotes.
hasattachment:yesItems that have attachments. You can also use hasattachment:true to get the same results.
attachments:presentation.pptxItems that have attachments named presentation.pptx or if the attachment contains presentation.pptx within its contents.
subject:"bobby moore" Items whose subject contains the phrase bobby moore.
subject:bobby moore Items with bobby in the subject line and with moore anywhere else in the document.
cc:"bobby more"Items in which the display name bobby moore is on the Cc line.
cc:bobbymoore@contoso.comItems in which the e-mail address bobbymoore@contoso.com is on the Cc line.
bcc:bobbyItems in which bobby is on the Bcc line.
messagesize:<10 KBItems whose size is less than 10 kilobytes. Note the use of the "less than" comparison operator (<).
messagesize:>5 MBItems whose size is larger than 5 megabytes. Note the use of the "greater than" comparison operator (>).
received:=1/1/2006Items that arrived on 1/1/2006. Note the use of the "equals" comparison operator (=).
received:yesterday Items that arrived yesterday. Instant Search also recognizes the follow date values:
  • Relative dates: For example, today, tomorrow, yesterday
  • Multi-word relative dates: For example, this week, next month, last week, past month, coming year
  • Days: Sunday, Monday ... Saturday
  • Months: January, February ... December
received:last weekItems that arrived last week. Note that if you run this query again a month from now you will obtain different results because it is a time relative query.
due:last weekItems that are flagged for follow up a due date.
messagesize:tinyItems whose size is less than 10 kilobytes
messagesize:smallItems whose size is between 10 and 25 kilobytes
messagesize:mediumItems whose size is between 25 and 100 kilobytes
messagesize:largeItems whose size is between 100 and 500 kilobytes
messagesize:verylargeItems whose size is between 500 kilobytes and 1 megabyte
followupflag:follow upItems that are flagged for follow up.
messagesize:enormous Items whose size is larger than 5 megabytes
hasflag:trueItems that are flagged for follow up.
from:bobby (received:1/7/05 OR received:1/8/05)Items from bobby that arrived on either 1/7/05 or 1/8/05. Note the use of parentheses to group the dates.
received:>=10/1/06 AND received:<=10/5/06Items that arrived between 10/1/06 and 10/5/06.
received:>10/1/06 AND received:<10/5/06Items that arrived after 10/1/06 but before 10/5/06.
sent: yesterdayItems that you sent yesterday.
to:bobbyItems that you sent to bobby when you are searching in the Sent Items folder.
read:noItems that have not been read. You can also use read:false to get the same results.
subject:status received:MayItems received from anyone during the month of May (any year) where the subject contains status.
startdate:next week subject:statusCalendar items next week where the subject contains status.
is:recurringCalendar items that are recurring.
organizer:bobbyCalendar items where bobby is the organizer.
category:businessItems that are categorized as business.
firstname:bobbyContacts that contain bobby in the First Name field.
lastname:mooreContacts that contain moore in the Last Name field.
nickname:bobbyContacts that contain bobby in the Nickname field.
jobtitle:physicianContacts that contain physician in the Job Title field.
pager:555-0100 Contacts that contain 555-0100 in the Pager field.
businessphone:555-0100 Contacts that contain 555-0100 in the Business Phone field.
homephone:555-0100 Contacts that contain 555-0100 in the Home Phone field.
mobilephone:555-0100 Contacts that contain 555-0100 in the Mobile Phone field.
carphone:555-0100 Contacts that contain 555-0100 in the Car Phone field.
businessfax:555-0100 Contacts that contain 555-0100 in the Business Fax field.
homefax:555-0100 Contacts that contain 555-0100 in the Home Fax field.
businessaddress:(4567 Main St., Buffalo, NY 98052)Contacts that contain 4567 Main St., Buffalo, NY 98052 in the Business Address field. Note the use of parentheses to enclose the address.
homeaddress:(4567 Main St., Buffalo, NY 98052)Contacts that contain 4567 Main St., Buffalo, NY 98052 in the Home Address field. Note the use of parentheses to enclose the address.
businesscity:buffaloContacts that contain buffalo in the Business City field.
businesspostalcode:98052Contacts that contain 98052 in the Business Postal Code field.
street:(4567 Main St)Contacts that contain 4567 Main St in the Business Address Street field. Note the use of parentheses to enclose the address.
homestreet:(4567 Main St)Contacts that contain 4567 Main St in the Home Address Street field. Note the use of parentheses to enclose the address.
birthday:6/4/1960Contacts that contain 6/4/1960 in the Birthday field.
webpage:www.contoso.comContacts that contain the URL www.contoso.com in the Web Page Address field.

segunda-feira, agosto 26, 2013

SQL Server - Como evitar que um query fique registado no "Transaction Log"

Quando se executam comandos em BD a 1ª linha aqui a bold consegue evitar que o transaction log seja afetado:


SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

SELECT *  FROM Table1
  WHERE colName1 LIKE '%AA%'
  ORDER BY colName2 ASC

terça-feira, agosto 06, 2013

Route Table Add and Delete Commands

Para adicionar rotas de encaminhamento de trafego em servidores com várias nics deverão utilizar o seguinte comando:

==> Adicionar Rota
route -p add 10.10.17.55 mask 255.255.255.255 10.10.17.1 metric 10 if 1

==> Adicionar Rota sem definição da métrica (ordem) e sem interface (Windows escolhe a melhor):
route -p add 10.10.17.55 mask 255.255.255.255 10.10.17.1


==> Se for preciso remover
route -p delete 10.10.17.55

Nota: o -p faz a rota ser persistente em caso de reboot do servidor e deve ser colocar no comando add ou delete caso seja uma das rotas persistentes

Para testar:


C:\Windows\system32>tracert 212.18.177.55
Tracing route to 212.18.177.55 over a maximum of 30 hops
  1    <1 ms    <1 ms    <1 ms  10.10.17.1
  2     *        *

Deverá estar a contatar o gatway que definiram, senão, usem route print 10.* e verifiquem se está alguma rota que o influenci primeiro na metrica.


Help da Microsoft:
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/route.mspx?mfr=true


Subnet Calculator:
http://portal.monitis.com/free-tools/ip-subnet


Exemplos:
http://www.itino.net/add-and-remove-persistent-static-routes-in-microsoft-windows/

Video explicativo:
http://www.youtube.com/watch?v=uOqBollh_x4

quinta-feira, julho 11, 2013

How to format date with getdate() function result

How to format date with getdate() function result:

SELECT replace(convert(varchar, getdate(), 111), '/', '-')  + ' 00:00:00' AS EndDate, replace(convert(varchar, getdate()-1, 111), '/', '-') + ' 00:00:00' AS StartDate


http://anubhavg.wordpress.com/2009/06/11/how-to-format-datetime-date-in-sql-server-2005/

terça-feira, julho 09, 2013

SCOM Reporting - How To get Performance counters by Day instead of Hour


To get Performance counters by Day instead of Hour:

SELECT FullName, InstanceName, DateTime, AverageValue, MaxValue, MinValue
FROM OperationsManagerDW.dbo.vManagedEntity,
OperationsManagerDW.dbo.vPerformanceRule,
OperationsManagerDW.dbo.vPerformanceRuleInstance,
OperationsManagerDW.Perf.vPerfDaily
WHERE vPerfDaily.ManagedEntityRowId = vManagedEntity.ManagedEntityRowId
AND vPerfDaily.PerformanceRuleInstanceRowId = vPerformanceRuleInstance.PerformanceRuleInstanceRowId
AND vPerformanceRuleInstance.RuleRowId = vPerformanceRule.RuleRowId
AND vPerformanceRule.ObjectName = 'Processor'
AND vPerformanceRule.CounterName = '% Processor Time'
AND DateTime > '2013-06-01'
AND DateTime < '2013-07-01'
ORDER BY FullName, InstanceName, DateTime

sexta-feira, julho 05, 2013

SCOM Reporting - How to get Performance Counter

http://capacitas.wordpress.com/2012/12/05/retrieving-data-from-the-scom-database/

You can now construct a query to get back, for instance, CPU data for every server between two dates (knocked together quickly to show how it all links up, you could probably write one more elegantly):
SELECT FullName, InstanceName, DateTime, AverageValue
FROM OperationsManagerDW.dbo.vManagedEntity,
OperationsManagerDW.dbo.vPerformanceRule,
OperationsManagerDW.dbo.vPerformanceRuleInstance,
OperationsManagerDW.Perf.vPerfHourly
WHERE vPerfHourly.ManagedEntityRowId = vManagedEntity.ManagedEntityRowId
AND vPerfHourly.PerformanceRuleInstanceRowId = vPerformanceRuleInstance.PerformanceRuleInstanceRowId
AND vPerformanceRuleInstance.RuleRowId = vPerformanceRule.RuleRowId
AND vPerformanceRule.ObjectName = ‘Processor’
AND vPerformanceRule.CounterName = ‘% Processor Time’
AND DateTime > ’2012-11-01′
AND DateTime < ’2012-11-08′
ORDER BY FullName, InstanceName, DateTime

quarta-feira, julho 03, 2013

APPFabric - A nova tecnologia de Caching

Cache Administration with Windows PowerShell (Windows Server AppFabric Caching)

           
By using Windows PowerShell, you can administer the cache cluster, cache hosts, and the cache itself. If you are using a computer with the Cache Administration feature installed, there are two ways of using Windows PowerShell for managing the caching features of AppFabric. On the Start Menu, go to Administrative Tools, and then select Windows PowerShell Modules. Or you can go to the Start Menu, click All Programs, Windows Server AppFabric, and then click Caching Administration Windows PowerShell.

Commands

http://msdn.microsoft.com/en-us/library/ff718177(v=azure.10).aspx

How to know if the caching is healthy


http://msdn.microsoft.com/en-us/library/ff921010(v=azure.10).aspx

Throttling Troubleshooting (Windows Server AppFabric Caching)


http://msdn.microsoft.com/en-us/library/ff921030(v=azure.10).aspx

segunda-feira, junho 24, 2013

How to get Username by Serial

To get the Username by Serial you show use this command:


by user
   wmic useraccount get name,sid
by group
   wmic usergroup get name,sid


Works fine :)