Monday, March 26, 2012
Query Governor
Im setting up a SQL-Server and there is an option named Query
Governor to avoid queries to exceed a specific cost. How is this cost
measured ? Milliseconds ?
best regards,
Evandro
You can set this in enterprise manager under server properties using the
server settings tab.
Or
EXEC sp_configure 'show advanced option', '1'
exec sp_configure N'query governor cost limit', 100 (or the max elapsed time
in seconds)
http://www.schemamania.org/jkl/books..._server_51.htm
http://msdn.microsoft.com/library/de...onfig_73u6.asp
"Evandro Braga" <evandro_braga@.hotmail.com> wrote in message
news:eBM64z28EHA.1396@.tk2msftngp13.phx.gbl...
> Hello all,
> Im setting up a SQL-Server and there is an option named Query
> Governor to avoid queries to exceed a specific cost. How is this cost
> measured ? Milliseconds ?
>
> best regards,
> Evandro
>
|||Hi Evandro,
EXEC sp_configure N'query governor cost limit', 100 is a server-wide
setting. Unless you have a very specific reason, do not set this option.
At the client level, statementwise one can use
SET QUERY_GOVERNOR_COST_LIMIT
Thanks
Yogish
Query Governor
I´m setting up a SQL-Server and there is an option named Query
Governor to avoid queries to exceed a specific cost. How is this cost
measured ? Milliseconds ?
best regards,
EvandroYou can set this in enterprise manager under server properties using the
server settings tab.
Or
EXEC sp_configure 'show advanced option', '1'
exec sp_configure N'query governor cost limit', 100 (or the max elapsed time
in seconds)
http://www.schemamania.org/jkl/booksonline/SQLBOL70/html/1_server_51.htm
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adminsql/ad_config_73u6.asp
"Evandro Braga" <evandro_braga@.hotmail.com> wrote in message
news:eBM64z28EHA.1396@.tk2msftngp13.phx.gbl...
> Hello all,
> I´m setting up a SQL-Server and there is an option named Query
> Governor to avoid queries to exceed a specific cost. How is this cost
> measured ? Milliseconds ?
>
> best regards,
> Evandro
>|||Hi Evandro,
EXEC sp_configure N'query governor cost limit', 100 is a server-wide
setting. Unless you have a very specific reason, do not set this option.
At the client level, statementwise one can use
SET QUERY_GOVERNOR_COST_LIMIT
--
Thanks
Yogishsql
Query Governor
Im setting up a SQL-Server and there is an option named Query
Governor to avoid queries to exceed a specific cost. How is this cost
measured ? Milliseconds ?
best regards,
EvandroYou can set this in enterprise manager under server properties using the
server settings tab.
Or
EXEC sp_configure 'show advanced option', '1'
exec sp_configure N'query governor cost limit', 100 (or the max elapsed time
in seconds)
http://www.schemamania.org/jkl/book...1_server_51.htm
http://msdn.microsoft.com/library/d... />
g_73u6.asp
"Evandro Braga" <evandro_braga@.hotmail.com> wrote in message
news:eBM64z28EHA.1396@.tk2msftngp13.phx.gbl...
> Hello all,
> Im setting up a SQL-Server and there is an option named Query
> Governor to avoid queries to exceed a specific cost. How is this cost
> measured ? Milliseconds ?
>
> best regards,
> Evandro
>|||Hi Evandro,
EXEC sp_configure N'query governor cost limit', 100 is a server-wide
setting. Unless you have a very specific reason, do not set this option.
At the client level, statementwise one can use
SET QUERY_GOVERNOR_COST_LIMIT
Thanks
Yogish
Friday, March 9, 2012
Query DateTime DataType for Current or Future Events
I have a sql server express 2005 database with a table named Events with a column named Date (datetime datatype). I want a query that will display all rows that are either current or future but not past. I suspect there is a simple way of doing this. As a Newbie searching archived threads this is what I have come up with so far. I determine the number of days from present:
SELECTDATEDIFF(day, Date,GETDATE())AS NumberOfDays
FROMEvents
This yields number of days from present with positive numbers in the past and negative numbers in the future. Thus setting a WHERE clause to <= 0 would limit my results to present or future events. Something like this:
SELECT*
FROM Events
WhereDATEDIFF(day, Date,GETDATE())AS NumberOfDays<= 0
The error message states: "Incorrect syntax near the keyword 'AS'"
This feels like a clumsy way to approach this problem, but I have to start where I am.
Any suggestions on how to proceed will be greatly appreciated.
SELECT*FROM EventsWhereDATEDIFF(day, Date,GETDATE())<= 0
or
select*FROM EventsWHERE Date>=GETDATE()
|||Thanks limno. Exactly what I needed.Saturday, February 25, 2012
Query by quarter
There is a table named INCOME that has INCOME column for each day and DATE column starting from Aug. 29 1980. How to calculate income summary by each quarter? Thanks.
ZYTDefine quarter. Are you a calendar year quarter, fiscal 4434 or 4344? When does your year begin and end?
After you find that out,
SELECT
SUM(CASE WHEN date BETWEEN @.q1begin AND @.q1end THEN income ELSE 0 END) AS q1,
SUM(CASE WHEN date BETWEEN @.q2begin AND @.q2end THEN income ELSE 0 END) AS q2,
SUM(CASE WHEN date BETWEEN @.q3begin AND @.q3end THEN income ELSE 0 END) AS q3,
SUM(CASE WHEN date BETWEEN @.q4begin AND @.q4end THEN income ELSE 0 END) AS q4
FROM
that_table|||Maybe something like this, though I haven't tested the syntax:
select cast(Month([IncomeDate])/4 as int) as Quarter|||The following dates are UK-Defined Quarter Day
25 March (Lady Day),
24 June (Midsummer Day),
29 September (Michaelmas), and 25 December (Christmas Day).
Try this stored procedure
Create Proc usp_QuarterIncome
As
Set Nocount On
Create Table #Quarter_Income(Id int identity(1,1),Quarters datetime,QuarterIncome money)
insert into #Quarter_Income (Quarters)
select distinct datename(yy,date)+'/'+convert(varchar(2),datepart(mm,date))+'/'+
case datepart(mm,date) when 3 then '25' when 6 then '24' when 9 then '29' when 12 then '25' end as Quarter
from income where datepart(mm,date) in (3,6,9,12)
declare @.id int,
@.StartDate Datetime,
@.Start DateTime,
@.EndDate Datetime,
@.Sum money
Select @.Start = Min(Date) From Income
set @.id = 0
while @.Id < (select max(id) from #quarter_Income)
begin
Select @.StartDate= Quarters From #quarter_Income where Id = @.Id
Select @.EndDate = Quarters From #quarter_Income where Id = @.Id+1
Select @.Sum = Sum(Income) From Income where [Date] >= isnull(@.StartDate,@.Start) and [Date] < @.EndDate
Update #quarter_Income Set QuarterIncome = @.Sum where Id = @.Id+1
Set @.Id = @.id + 1
End
Select Quarters,QuarterIncome from #quarter_Income
Set Nocount Off
--Usage:
--Exec usp_QuarterIncome|||What is the problem with
select sum(income),datepart(qq,date),year(date) from income group by datepart(qq,date),year(date)|||Humph! Sure, any shmuck can use the fancy-pants "built-in functions". But where is the challenge in that? If you are lucky, tomorrow I will post my innovative cursor-based dynamic SQL function for removing leading spaces from strings.|||You will need to write another one for the trailing spaces ... I will need that too ...|||you guy's are geniuses!!!|||What is the problem with
select sum(income),datepart(qq,date),year(date) from income group by datepart(qq,date),year(date)
Man, I like the way that you think!
-PatP|||Humph! Sure, any shmuck can use the fancy-pants "built-in functions". But where is the challenge in that? If you are lucky, tomorrow I will post my innovative cursor-based dynamic SQL function for removing leading spaces from strings.
I almost fell outta my chair... I could've hurt myself! Hysterical laughter at work implies insanity... I hope no one noticed...