Showing posts with label date. Show all posts
Showing posts with label date. Show all posts

Thursday, March 29, 2012

db backup simple vs. full recovery mode

When we do a full database backup manually, we are seeing the trn file reflect the current date/time, but we are not seeing the mdf reflect the new date/time. And we are not seeing the transaction log file decrease in size. the recovery mode is set to full, do we need to change to simple to see both the mdf being backup'ed?

When you do a backup, markers are written to the Transaction Log file, however, the backup process does not change anything about the datafiles -therefore the 'trn' file gets a new datetime and the data file does not.

The Transaction Log file does not shrink UNLESS specifically so instructed. See Books Online for DBCC 'Shrinkfile'.

|||

Hi,

You can schedule half/hourly t-log backup to keep it in shape, how ever if its growing unpexctingly refer below thread:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1221599&SiteID=1

Hemantgiri S. Goswami

|||

What we are seeing are current timestamps on the trn file, current timestamps on the ldf, but about a six month old modified date on the mdf. I would assume that the trn file would have the most recent transactions, the ldf the intermediate, and then the mdf.

With the truncate command on the trn file, do the transactions immediately hit the mdf file or the ldf (I would think the ldf)? however when does the mdf get updated by the ldf file?

Am I completely lost--I thought that the ldf (a locked mdf file, correct?) would eventually post the edits/updates to the mdf.

|||

The ldf is the transaction log file. Data changes are moved to the mdf (data file) on a regular basis -usually within seconds.

The OS stamps the file date. SQL Server has a data file (mdf) open with a, perhaps, large, amount of empty space. The OS does not know what is happening inside the mdf file unless there are specific interactions between SQL Server and the OS regarding the file.

It seems like you are confused because the mdf file date is not changing. It most likely will not change unless one of the following actions occur: Filegrowth, Fileshrink, Detach/Attach.

Tuesday, March 27, 2012

days between dates from a list

Hi,
I am trying to perform an interpolation of counts between event dates...my
data looks like this:
Event Date Count
1/1/06 13
1/17/06 9
2/3/06 7 etc...
The spacing of event date is not always equal thus I need to be able to do
something like this: (date1-nextdate). I don't know how to select the next
date. Any help if greatly appreciated.
Jen...learning
This might work and be fast if event date is a PK or indexed:
SELECT
E.[EventDate], E.[CountOfThings], dbo.ufn_NextEvent(E.[EventDate]) AS
NextDate
FROM
Events E
Where dbo.ufn_NextEvent is a user defined function like:
CREATE FUNCTION [dbo].[ufn_NextEvent]
(
@.ThisEvent DATETIME
)
RETURNS DATETIME
AS
BEGIN
DECLARE @.result DATETIME
SELECT TOP 1 @.result = [EventDate] FROM Events WHERE [EventDate] > @.ThisEvent
RETURN (@.result)
END
Result set is:
2006-01-01 00:00:00.000132006-01-17 00:00:00.000
2006-01-17 00:00:00.00092006-02-03 00:00:00.000
2006-02-03 00:00:00.0007NULL
Regards,
JayAchTee
"jennifer.heintz" wrote:

> Hi,
> I am trying to perform an interpolation of counts between event dates...my
> data looks like this:
> Event Date Count
> 1/1/06 13
> 1/17/06 9
> 2/3/06 7 etc...
> The spacing of event date is not always equal thus I need to be able to do
> something like this: (date1-nextdate). I don't know how to select the next
> date. Any help if greatly appreciated.
> --
> Jen...learning

DayOfWeek Function

Would like to set a date parameter default in the report designer based on
the day of the week. So if it was Monday, then the default date would be set
to =today.adddays(-3) otherwise it would default to =today.adddays(-1). Is
there a dayOfWeek function that be used in an expression that returns either
the numeric or the alpha of the week?
GlassHi,
You can easely use the expression <code>=WeekDay(Now())</code> for
retrieving the actual weekday. This combined with an IIF expression you can
create the behaviour you need, like
<code>
=IIF(WeekDay(Now())=2, Now.AddDays(-3), Now.AddDays(-1))
</code>
Hope this would help you
Jan Pieter Posthuma
"Glass" wrote:
> Would like to set a date parameter default in the report designer based on
> the day of the week. So if it was Monday, then the default date would be set
> to =today.adddays(-3) otherwise it would default to =today.adddays(-1). Is
> there a dayOfWeek function that be used in an expression that returns either
> the numeric or the alpha of the week?
> Glass|||Jan Pieter... It worked great. Have two ancillary question: what is the
difference between today and now? Is there a list of functions that are
valid in report server for use in expressions? Online books didn't seem to
help here.
Appreciate the help...
Glass
"Jan Pieter Posthuma" wrote:
> Hi,
> You can easely use the expression <code>=WeekDay(Now())</code> for
> retrieving the actual weekday. This combined with an IIF expression you can
> create the behaviour you need, like
> <code>
> =IIF(WeekDay(Now())=2, Now.AddDays(-3), Now.AddDays(-1))
> </code>
> Hope this would help you
> Jan Pieter Posthuma
>
> "Glass" wrote:
> > Would like to set a date parameter default in the report designer based on
> > the day of the week. So if it was Monday, then the default date would be set
> > to =today.adddays(-3) otherwise it would default to =today.adddays(-1). Is
> > there a dayOfWeek function that be used in an expression that returns either
> > the numeric or the alpha of the week?
> >
> > Glass|||Glass,
There is a little difference between Now() and Today(). Both return the same
date, but Now returns the actual time and Today will allways return 12AM
back. So for today:
=Now() returns 6/22/2005 9:55:04 AM
=Today() returns 6/22/2005 12:00:00 AM
I must say: I use Now mainly because of my history with VB.NET.
Jan Pieter Posthuma
"Glass" wrote:
> Jan Pieter... It worked great. Have two ancillary question: what is the
> difference between today and now? Is there a list of functions that are
> valid in report server for use in expressions? Online books didn't seem to
> help here.
> Appreciate the help...
> Glass
> "Jan Pieter Posthuma" wrote:
> > Hi,
> >
> > You can easely use the expression <code>=WeekDay(Now())</code> for
> > retrieving the actual weekday. This combined with an IIF expression you can
> > create the behaviour you need, like
> > <code>
> > =IIF(WeekDay(Now())=2, Now.AddDays(-3), Now.AddDays(-1))
> > </code>
> >
> > Hope this would help you
> >
> > Jan Pieter Posthuma
> >
> >
> >
> > "Glass" wrote:
> >
> > > Would like to set a date parameter default in the report designer based on
> > > the day of the week. So if it was Monday, then the default date would be set
> > > to =today.adddays(-3) otherwise it would default to =today.adddays(-1). Is
> > > there a dayOfWeek function that be used in an expression that returns either
> > > the numeric or the alpha of the week?
> > >
> > > Glass|||Thank you very much...
Glass
"Jan Pieter Posthuma" wrote:
> Glass,
> There is a little difference between Now() and Today(). Both return the same
> date, but Now returns the actual time and Today will allways return 12AM
> back. So for today:
> =Now() returns 6/22/2005 9:55:04 AM
> =Today() returns 6/22/2005 12:00:00 AM
> I must say: I use Now mainly because of my history with VB.NET.
> Jan Pieter Posthuma
> "Glass" wrote:
> > Jan Pieter... It worked great. Have two ancillary question: what is the
> > difference between today and now? Is there a list of functions that are
> > valid in report server for use in expressions? Online books didn't seem to
> > help here.
> >
> > Appreciate the help...
> >
> > Glass
> >
> > "Jan Pieter Posthuma" wrote:
> >
> > > Hi,
> > >
> > > You can easely use the expression <code>=WeekDay(Now())</code> for
> > > retrieving the actual weekday. This combined with an IIF expression you can
> > > create the behaviour you need, like
> > > <code>
> > > =IIF(WeekDay(Now())=2, Now.AddDays(-3), Now.AddDays(-1))
> > > </code>
> > >
> > > Hope this would help you
> > >
> > > Jan Pieter Posthuma
> > >
> > >
> > >
> > > "Glass" wrote:
> > >
> > > > Would like to set a date parameter default in the report designer based on
> > > > the day of the week. So if it was Monday, then the default date would be set
> > > > to =today.adddays(-3) otherwise it would default to =today.adddays(-1). Is
> > > > there a dayOfWeek function that be used in an expression that returns either
> > > > the numeric or the alpha of the week?
> > > >
> > > > Glass|||"Glass" skrev:
> Thank you very much...
> Glass
> "Jan Pieter Posthuma" wrote:
> > Glass,
> >
> > There is a little difference between Now() and Today(). Both return the same
> > date, but Now returns the actual time and Today will allways return 12AM
> > back. So for today:
> > =Now() returns 6/22/2005 9:55:04 AM
> > =Today() returns 6/22/2005 12:00:00 AM
> >
> > I must say: I use Now mainly because of my history with VB.NET.
> >
> > Jan Pieter Posthuma
> >
> > "Glass" wrote:
> >
> > > Jan Pieter... It worked great. Have two ancillary question: what is the
> > > difference between today and now? Is there a list of functions that are
> > > valid in report server for use in expressions? Online books didn't seem to
> > > help here.
> > >
> > > Appreciate the help...
> > >
> > > Glass
> > >
> > > "Jan Pieter Posthuma" wrote:
> > >
> > > > Hi,
> > > >
> > > > You can easely use the expression <code>=WeekDay(Now())</code> for
> > > > retrieving the actual weekday. This combined with an IIF expression you can
> > > > create the behaviour you need, like
> > > > <code>
> > > > =IIF(WeekDay(Now())=2, Now.AddDays(-3), Now.AddDays(-1))
> > > > </code>
> > > >
> > > > Hope this would help you
> > > >
> > > > Jan Pieter Posthuma
> > > >
> > > >
> > > >
> > > > "Glass" wrote:
> > > >
> > > > > Would like to set a date parameter default in the report designer based on
> > > > > the day of the week. So if it was Monday, then the default date would be set
> > > > > to =today.adddays(-3) otherwise it would default to =today.adddays(-1). Is
> > > > > there a dayOfWeek function that be used in an expression that returns either
> > > > > the numeric or the alpha of the week?
> > > > >
> > > > > Glass
anna jag behöver verkligen din hjälp nuu !!sql

Sunday, March 25, 2012

Daylight Savings Date Change

I have a Windows 2003 Standard server running MS SQL 2000 Server on it. I
read that if I have MS SQL Server Notification Services running on it I will
need to apply an update to it for the daylight savings time date change. Ho
w
do I tell if I have Notification Services running on this server. I don't
see it in Services. Is there anywhere else I need to look or is that it?
Thank you in advance.
--
Mike StevensYou would see it as a separately installed program in "Add/Remove Programs"
if you are on SQL Server
2000.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Stevens" <Stevens@.discussions.microsoft.com> wrote in message
news:D66848A1-E298-4A6E-AB6A-2085835741B0@.microsoft.com...
>I have a Windows 2003 Standard server running MS SQL 2000 Server on it. I
> read that if I have MS SQL Server Notification Services running on it I wi
ll
> need to apply an update to it for the daylight savings time date change.
How
> do I tell if I have Notification Services running on this server. I don't
> see it in Services. Is there anywhere else I need to look or is that it?
> Thank you in advance.
> --
> Mike Stevens|||In addition to the note from Tibor, you will have some databases like
NSMain* and NS*. The KB article that has the fix includes a section on
detecting if Notification Services is installed on SQL Server 2000:
http://support.microsoft.com/kb/931815
HTH,
Plamen Ratchev
http://www.SQLStudio.com|||That answered my question. Thank you for your help.
--
Mike Stevens
"Tibor Karaszi" wrote:

> You would see it as a separately installed program in "Add/Remove Programs
" if you are on SQL Server
> 2000.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
>
> "Stevens" <Stevens@.discussions.microsoft.com> wrote in message
> news:D66848A1-E298-4A6E-AB6A-2085835741B0@.microsoft.com...
>
>|||Thank you for your help. It doesn't look like I have it. One less thing to
do.
--
Mike Stevens
"Plamen Ratchev" wrote:

> In addition to the note from Tibor, you will have some databases like
> NSMain* and NS*. The KB article that has the fix includes a section on
> detecting if Notification Services is installed on SQL Server 2000:
> http://support.microsoft.com/kb/931815
> HTH,
> Plamen Ratchev
> http://www.SQLStudio.com
>
>|||Plamen,
Can you install SQL2005 Notification Services but not configure it? If
that's so then this is what we have done so we should not have to run the
script in the KB article.
Chris
"Plamen Ratchev" <Plamen@.SQLStudio.com> wrote in message
news:OBOgOXuSHHA.5016@.TK2MSFTNGP05.phx.gbl...
> In addition to the note from Tibor, you will have some databases like
> NSMain* and NS*. The KB article that has the fix includes a section on
> detecting if Notification Services is installed on SQL Server 2000:
> http://support.microsoft.com/kb/931815
> HTH,
> Plamen Ratchev
> http://www.SQLStudio.com
>
>|||You are correct Chris. When you install Notification Services only the
binary files are installed. You have to worry about applying the fix only
when you configure and deploy instances of Notification Services, which host
notification applications. Also, note in the KB that new instances created
after SP2 will not need to be fixed, as they will have the correct
information.
Regards,
Plamen Ratchev
http://www.SQLStudio.com|||Thanks Plamen.
That's what I had hoped for.
Chris
"Plamen Ratchev" <Plamen@.SQLStudio.com> wrote in message
news:%239ANydwSHHA.4260@.TK2MSFTNGP06.phx.gbl...
> You are correct Chris. When you install Notification Services only the
> binary files are installed. You have to worry about applying the fix only
> when you configure and deploy instances of Notification Services, which
> host notification applications. Also, note in the KB that new instances
> created after SP2 will not need to be fixed, as they will have the correct
> information.
> Regards,
> Plamen Ratchev
> http://www.SQLStudio.com
>

Daylight Savings Date Change

I have a Windows 2003 Standard server running MS SQL 2000 Server on it. I
read that if I have MS SQL Server Notification Services running on it I will
need to apply an update to it for the daylight savings time date change. How
do I tell if I have Notification Services running on this server. I don't
see it in Services. Is there anywhere else I need to look or is that it?
Thank you in advance.
Mike Stevens
In addition to the note from Tibor, you will have some databases like
NSMain* and NS*. The KB article that has the fix includes a section on
detecting if Notification Services is installed on SQL Server 2000:
http://support.microsoft.com/kb/931815
HTH,
Plamen Ratchev
http://www.SQLStudio.com
|||That answered my question. Thank you for your help.
Mike Stevens
"Tibor Karaszi" wrote:

> You would see it as a separately installed program in "Add/Remove Programs" if you are on SQL Server
> 2000.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
>
> "Stevens" <Stevens@.discussions.microsoft.com> wrote in message
> news:D66848A1-E298-4A6E-AB6A-2085835741B0@.microsoft.com...
>
>
|||Thank you for your help. It doesn't look like I have it. One less thing to
do.
Mike Stevens
"Plamen Ratchev" wrote:

> In addition to the note from Tibor, you will have some databases like
> NSMain* and NS*. The KB article that has the fix includes a section on
> detecting if Notification Services is installed on SQL Server 2000:
> http://support.microsoft.com/kb/931815
> HTH,
> Plamen Ratchev
> http://www.SQLStudio.com
>
>
|||Plamen,
Can you install SQL2005 Notification Services but not configure it? If
that's so then this is what we have done so we should not have to run the
script in the KB article.
Chris
"Plamen Ratchev" <Plamen@.SQLStudio.com> wrote in message
news:OBOgOXuSHHA.5016@.TK2MSFTNGP05.phx.gbl...
> In addition to the note from Tibor, you will have some databases like
> NSMain* and NS*. The KB article that has the fix includes a section on
> detecting if Notification Services is installed on SQL Server 2000:
> http://support.microsoft.com/kb/931815
> HTH,
> Plamen Ratchev
> http://www.SQLStudio.com
>
>
|||You are correct Chris. When you install Notification Services only the
binary files are installed. You have to worry about applying the fix only
when you configure and deploy instances of Notification Services, which host
notification applications. Also, note in the KB that new instances created
after SP2 will not need to be fixed, as they will have the correct
information.
Regards,
Plamen Ratchev
http://www.SQLStudio.com
|||Thanks Plamen.
That's what I had hoped for.
Chris
"Plamen Ratchev" <Plamen@.SQLStudio.com> wrote in message
news:%239ANydwSHHA.4260@.TK2MSFTNGP06.phx.gbl...
> You are correct Chris. When you install Notification Services only the
> binary files are installed. You have to worry about applying the fix only
> when you configure and deploy instances of Notification Services, which
> host notification applications. Also, note in the KB that new instances
> created after SP2 will not need to be fixed, as they will have the correct
> information.
> Regards,
> Plamen Ratchev
> http://www.SQLStudio.com
>
sql

Daylight Savings Date Change

I have a Windows 2003 Standard server running MS SQL 2000 Server on it. I
read that if I have MS SQL Server Notification Services running on it I will
need to apply an update to it for the daylight savings time date change. How
do I tell if I have Notification Services running on this server. I don't
see it in Services. Is there anywhere else I need to look or is that it?
Thank you in advance.
--
Mike StevensYou would see it as a separately installed program in "Add/Remove Programs" if you are on SQL Server
2000.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Stevens" <Stevens@.discussions.microsoft.com> wrote in message
news:D66848A1-E298-4A6E-AB6A-2085835741B0@.microsoft.com...
>I have a Windows 2003 Standard server running MS SQL 2000 Server on it. I
> read that if I have MS SQL Server Notification Services running on it I will
> need to apply an update to it for the daylight savings time date change. How
> do I tell if I have Notification Services running on this server. I don't
> see it in Services. Is there anywhere else I need to look or is that it?
> Thank you in advance.
> --
> Mike Stevens|||In addition to the note from Tibor, you will have some databases like
NSMain* and NS*. The KB article that has the fix includes a section on
detecting if Notification Services is installed on SQL Server 2000:
http://support.microsoft.com/kb/931815
HTH,
Plamen Ratchev
http://www.SQLStudio.com|||That answered my question. Thank you for your help.
--
Mike Stevens
"Tibor Karaszi" wrote:
> You would see it as a separately installed program in "Add/Remove Programs" if you are on SQL Server
> 2000.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
>
> "Stevens" <Stevens@.discussions.microsoft.com> wrote in message
> news:D66848A1-E298-4A6E-AB6A-2085835741B0@.microsoft.com...
> >I have a Windows 2003 Standard server running MS SQL 2000 Server on it. I
> > read that if I have MS SQL Server Notification Services running on it I will
> > need to apply an update to it for the daylight savings time date change. How
> > do I tell if I have Notification Services running on this server. I don't
> > see it in Services. Is there anywhere else I need to look or is that it?
> >
> > Thank you in advance.
> > --
> > Mike Stevens
>
>|||Thank you for your help. It doesn't look like I have it. One less thing to
do.
--
Mike Stevens
"Plamen Ratchev" wrote:
> In addition to the note from Tibor, you will have some databases like
> NSMain* and NS*. The KB article that has the fix includes a section on
> detecting if Notification Services is installed on SQL Server 2000:
> http://support.microsoft.com/kb/931815
> HTH,
> Plamen Ratchev
> http://www.SQLStudio.com
>
>|||Plamen,
Can you install SQL2005 Notification Services but not configure it? If
that's so then this is what we have done so we should not have to run the
script in the KB article.
Chris
"Plamen Ratchev" <Plamen@.SQLStudio.com> wrote in message
news:OBOgOXuSHHA.5016@.TK2MSFTNGP05.phx.gbl...
> In addition to the note from Tibor, you will have some databases like
> NSMain* and NS*. The KB article that has the fix includes a section on
> detecting if Notification Services is installed on SQL Server 2000:
> http://support.microsoft.com/kb/931815
> HTH,
> Plamen Ratchev
> http://www.SQLStudio.com
>
>|||You are correct Chris. When you install Notification Services only the
binary files are installed. You have to worry about applying the fix only
when you configure and deploy instances of Notification Services, which host
notification applications. Also, note in the KB that new instances created
after SP2 will not need to be fixed, as they will have the correct
information.
Regards,
Plamen Ratchev
http://www.SQLStudio.com|||Thanks Plamen.
That's what I had hoped for.
Chris
"Plamen Ratchev" <Plamen@.SQLStudio.com> wrote in message
news:%239ANydwSHHA.4260@.TK2MSFTNGP06.phx.gbl...
> You are correct Chris. When you install Notification Services only the
> binary files are installed. You have to worry about applying the fix only
> when you configure and deploy instances of Notification Services, which
> host notification applications. Also, note in the KB that new instances
> created after SP2 will not need to be fixed, as they will have the correct
> information.
> Regards,
> Plamen Ratchev
> http://www.SQLStudio.com
>

Day of the week

I have a table whcih contains order Id (orderid_c), and order date
(orderdate_d).
Is there anywhere I can program to count the number of order from Monday to
the day the report is run, for example, when I run the report on Wednesday,
the report will cover from Monday to Wednesday and when I run the report on
Thursday, the report will cover from Monday to Thursday. I will have to run
the report several time during the business hour.
Thanks,set datefirst 1
select count(orderid_c) from table
where datepart(wk,orderdate_d) = datepart(wk,getdate())
"qjlee" <qjlee@.discussions.microsoft.com> wrote in message
news:9FCC02A9-29B8-48B1-B888-091BBC502CFD@.microsoft.com...
> I have a table whcih contains order Id (orderid_c), and order date
> (orderdate_d).
> Is there anywhere I can program to count the number of order from Monday
to
> the day the report is run, for example, when I run the report on
Wednesday,
> the report will cover from Monday to Wednesday and when I run the report
on
> Thursday, the report will cover from Monday to Thursday. I will have to
run
> the report several time during the business hour.
>
> Thanks,
>|||sp_who will tell you who and what database
"qjlee" wrote:

> I have a table whcih contains order Id (orderid_c), and order date
> (orderdate_d).
> Is there anywhere I can program to count the number of order from Monday t
o
> the day the report is run, for example, when I run the report on Wednesday
,
> the report will cover from Monday to Wednesday and when I run the report o
n
> Thursday, the report will cover from Monday to Thursday. I will have to r
un
> the report several time during the business hour.
>
> Thanks,
>|||On Thu, 18 Aug 2005 10:31:01 -0700, qjlee wrote:

>I have a table whcih contains order Id (orderid_c), and order date
>(orderdate_d).
>Is there anywhere I can program to count the number of order from Monday to
>the day the report is run, for example, when I run the report on Wednesday,
>the report will cover from Monday to Wednesday and when I run the report on
>Thursday, the report will cover from Monday to Thursday. I will have to ru
n
>the report several time during the business hour.
Hi qjlee,
Here's how to select data between "last monday" and "now":
SELECT ...
FROM ...
WHERE TheDate >= DATEADD(day, DATEDIFF(day, '20050103',
CURRENT_TIMESTAMP) / 7 * 7, '20050103')
AND TheDate <= CURRENT_TIMESTAMP
AMD ...
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)sql

Day of the week

Hi group ,
Please let me know which formule is usefull for calculate the day of week
based in a date.
my date is datetime.
day = convert(int,MyDate) % 7
is't working
Look up DATENAME & DATEPART functions in SQL Server Books Online.
Anith
|||SELECT DATENAME(dw, getdate())
|||But I need the number of the week. thanks you anyway.
Best regard
MArio
"Julie" <anonymous@.discussions.microsoft.com> wrote in message
news:BBA8C3BE-0086-49B4-B109-843FEEBED93D@.microsoft.com...
> SELECT DATENAME(dw, getdate())
|||? number of the week, or day of the week? Your message and subject don't
agree.
In any case, as Anith suggested, look at DATENAME and DATEPART in Books
Online.
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"Mario Reiley" <mreiley@.cantv.net> wrote in message
news:#gi0eLENEHA.2640@.TK2MSFTNGP12.phx.gbl...
> But I need the number of the week. thanks you anyway.
|||I like this formula:
(@.@.DATEFIRST + DATEPART(dw, date) ) % 7
It is always
0 on Sunday
1 on Monday
2 on Monday
up to
6 on Friday

Day of the week

Hi group ,
Please let me know which formule is usefull for calculate the day of week
based in a date.
my date is datetime.
day = convert(int,MyDate) % 7
is't workingLook up DATENAME & DATEPART functions in SQL Server Books Online.
--
Anith|||But I need the number of the week. thanks you anyway.
Best regard
MArio
"Julie" <anonymous@.discussions.microsoft.com> wrote in message
news:BBA8C3BE-0086-49B4-B109-843FEEBED93D@.microsoft.com...
> SELECT DATENAME(dw, getdate())|||? number of the week, or day of the week? Your message and subject don't
agree.
In any case, as Anith suggested, look at DATENAME and DATEPART in Books
Online.
--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"Mario Reiley" <mreiley@.cantv.net> wrote in message
news:#gi0eLENEHA.2640@.TK2MSFTNGP12.phx.gbl...
> But I need the number of the week. thanks you anyway.sql

Day of the week

Hi group ,
Please let me know which formule is usefull for calculate the day of week
based in a date.
my date is datetime.
day = convert(int,MyDate) % 7
is't workingLook up DATENAME & DATEPART functions in SQL Server Books Online.
Anith|||SELECT DATENAME(dw, getdate())|||But I need the number of the week. thanks you anyway.
Best regard
MArio
"Julie" <anonymous@.discussions.microsoft.com> wrote in message
news:BBA8C3BE-0086-49B4-B109-843FEEBED93D@.microsoft.com...
> SELECT DATENAME(dw, getdate())|||? number of the week, or day of the week? Your message and subject don't
agree.
In any case, as Anith suggested, look at DATENAME and DATEPART in Books
Online.
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"Mario Reiley" <mreiley@.cantv.net> wrote in message
news:#gi0eLENEHA.2640@.TK2MSFTNGP12.phx.gbl...
> But I need the number of the week. thanks you anyway.|||I like this formula:
(@.@.DATEFIRST + DATEPART(dw, date) ) % 7
It is always
0 on Sunday
1 on Monday
2 on Monday
up to
6 on Friday

day name of a date

Hello,
One of my group field is a date, and I need to return day name, like Monday,
Tuesday, .. how can I do this?
Thanks,Imagine you have OrderDate; then the exression could be
=WeekDayName(WeekDay(Fields!OrderDate.Value))
--
Dejan Sarka, SQL Server MVP
Associate Mentor
www.SolidQualityLearning.com
"JIM.H." <JIMH@.discussions.microsoft.com> wrote in message
news:9F7027F2-7A04-4D0A-9176-63514D0599AA@.microsoft.com...
> Hello,
> One of my group field is a date, and I need to return day name, like
Monday,
> Tuesday, .. how can I do this?
> Thanks,
>sql

Thursday, March 22, 2012

Datum Variable

Hi,
how I can assign a date to a variable ?:o
I have no idea .... any smal tip ?
thx
thumbyou do not know this and it is time for mid terms. college gets more expensive and you get less out of it.

Declare @.MyVar datetime

SET @.MyVar = GETDATE()|||thanks for your answer and your time.

my problem was

DECLARE @.geburtstag DATETIME

SET @.geburtstag = '23.07.1968'

correctly is that

DECLARE @.geburtstag DATETIME

SET @.geburtstag = '23-07-1968'

thx

thumb

Dattime format problems when retrieved on FreeBSD server

I'm using MSSQL with PHP and this works fine on a Windows server.

When i move to a FreeBSD server, the date formatting is not working.

FreeBSD retrieves the date as: mon dd yyyy hh:mi:ss:mmmAM - and php's functions for formatting date fails.

I've tried using: Convert(varchar(10), Date, 103) AS Date, and the date is formatted fine - BUT sorting on date does NOT work.

Are there any way i can do changes to datetime behaviour on server side? I NEVER wants the date in mon dd yyyy hh:mi:ss:mmmAM. I don't need milliseconds, and i want 24h format - not AM/PM. Are there any settings on the SQL server for this?

Where are you doing your sorting? With T-SQL CONVERT-style affects sort:

ORDERBYConvert(nvarchar(30), OrderDate, 109)

|||

I'm not sure what you mean. I SELECT Convert(varchar(10), Date, 103) AS Date, and last sentence is ORDER BY Date DESC.

Anyway - i would prefer to fix this server-side if possible, so that i don't need to rewrite all queries adding convert functions etc...

|||If you want to ORDER BY the output of Convert(varchar(10), Date, 103) then you have to put that expression in the ODER BY clause not simply the column named Date.|||

I'll try that, but i don't think it will work, because it returns the date as a string, and thus sorting the strings from highest numbers, to lower, which does not not necessarily need to be correct(?)

Is this really the only reason to make it work?

Dattime format problems when retrieved on FreeBSD server

I'm using MSSQL with PHP and this works fine on a Windows server.

When i move to a FreeBSD server, the date formatting is not working.

FreeBSD retrieves the date as: mon dd yyyy hh:mi:ss:mmmAM - and php's functions for formatting date fails.

I've tried using: Convert(varchar(10), Date, 103) AS Date, and the date is formatted fine - BUT sorting on date does NOT work.

Are there any way i can do changes to datetime behaviour on server side? I NEVER wants the date in mon dd yyyy hh:mi:ss:mmmAM. I don't need milliseconds, and i want 24h format - not AM/PM. Are there any settings on the SQL server for this?

Where are you doing your sorting? With T-SQL CONVERT-style affects sort:

ORDERBYConvert(nvarchar(30), OrderDate, 109)

|||

I'm not sure what you mean. I SELECT Convert(varchar(10), Date, 103) AS Date, and last sentence is ORDER BY Date DESC.

Anyway - i would prefer to fix this server-side if possible, so that i don't need to rewrite all queries adding convert functions etc...

|||If you want to ORDER BY the output of Convert(varchar(10), Date, 103) then you have to put that expression in the ODER BY clause not simply the column named Date.|||

I'll try that, but i don't think it will work, because it returns the date as a string, and thus sorting the strings from highest numbers, to lower, which does not not necessarily need to be correct(?)

Is this really the only reason to make it work?

DateTimestamp

Hi,
I currently have a column in a table that is a default of getdate()). My
question : Is there a way to capture just the date without the time appended
?
For example, 04/04/2005. Question 2: How does SQL Server 2000 use indexes
on this datetimestamp field? Would a clustered index on this field help?
Almost all searching is done by the date field, whether it is searched by da
y
or a date range...Any better way than what is currently being done to help
with speed ? Currently we have a clustered index on this column. The column
currently contains approximately 12 million rows...
Thanks for your input,
WarrenChange the defualt to Cast (getdate() as Integer)
-- Datetimes as stored internally as a decimal value 4 bytes for the
integer portion, and another 4 bytes for the fractional portion. The 4 byte
s
for integer portion are the date, and the other 4 bytes are the time... So i
f
you cast the value to an integer, you truncate the time...
"Warren" wrote:

> Hi,
> I currently have a column in a table that is a default of getdate()). My
> question : Is there a way to capture just the date without the time append
ed?
> For example, 04/04/2005. Question 2: How does SQL Server 2000 use indexe
s
> on this datetimestamp field? Would a clustered index on this field help?
> Almost all searching is done by the date field, whether it is searched by
day
> or a date range...Any better way than what is currently being done to help
> with speed ? Currently we have a clustered index on this column. The colu
mn
> currently contains approximately 12 million rows...
> Thanks for your input,
> Warren|||Store same time for all rows.
Example:
use tempdb
go
create table dbo.t (
colA int not null identity unique,
colB datetime default (convert(char(8), getdate(), 112))
)
insert into t default values
WAITFOR DELAY '00:00:00.999'
insert into t default values
WAITFOR DELAY '00:00:00.999'
insert into t default values
select * from t
drop table t
go
If you are planning to do a lot of selects filtering this column based on a
range of dates, then having a clustered index by this column will be helpful
.
AMB
"Warren" wrote:

> Hi,
> I currently have a column in a table that is a default of getdate()). My
> question : Is there a way to capture just the date without the time append
ed?
> For example, 04/04/2005. Question 2: How does SQL Server 2000 use indexe
s
> on this datetimestamp field? Would a clustered index on this field help?
> Almost all searching is done by the date field, whether it is searched by
day
> or a date range...Any better way than what is currently being done to help
> with speed ? Currently we have a clustered index on this column. The colu
mn
> currently contains approximately 12 million rows...
> Thanks for your input,
> Warren|||There is no way to capture a date without the time portion; best thing to do
is probably write a function that sets each portion of the time to zero - us
e
DATEDIFF and DATEADD functions to subtract hours, minutes, seconds, and
milliseconds from the date.
With SQL 2000 32-bit datetimes are stored as 2 4-byte integers, so you can
convert the datetime to a binary(8), take the first 4 bytes and concat
0x00000000 to that and convert back to datetime to get zero hours, mins,
secs, & ms; but this method would not necessarily work on anything but SQL 2
k
32-bit.
As for a clustered index, only testing will tell...
KH
"Warren" wrote:

> Hi,
> I currently have a column in a table that is a default of getdate()). My
> question : Is there a way to capture just the date without the time append
ed?
> For example, 04/04/2005. Question 2: How does SQL Server 2000 use indexe
s
> on this datetimestamp field? Would a clustered index on this field help?
> Almost all searching is done by the date field, whether it is searched by
day
> or a date range...Any better way than what is currently being done to help
> with speed ? Currently we have a clustered index on this column. The colu
mn
> currently contains approximately 12 million rows...
> Thanks for your input,
> Warren|||If you're really interested in speed, don;t use DateTime column use an
integer or smallint.. and store the integer you get from Cast (getDate()
as Integer) directly. This reduces the size of the data in the column frm
8bytes to 4 bytes (oor 2 bytes if you use smallint) By reducing the width o
f
the index, you will dramatically increase the number of entries you will be
able to store on each IO Page of the index, and increase the performance
using the index.
NOTE: If you use smallints, then you need to subtract 32768 from the valu
you get from Cast(getdate() as Integer) before stuffing it into the smallint
field, because smallint is SIGNED 2-byte integer, but smalldatetime uses
UNSIGNED 2-byte integer..
SmallDatetime goes from Integer value 0 represesnting 1 jan 1900, to 65536
representing 6 June 2079... whereas smallint goes from -32768 to +32767...
Using Regular datetime is no problem, because it uses SIGNED 4-byte Integer,
with values from
January 1, 1753 through December 31, (this way value 0 still represents 1
Jan 1900... )
If your queries against this table often use date as a range of dates...
then a clustered index on this column will increase performance
draamatically.
"Warren" wrote:

> Hi,
> I currently have a column in a table that is a default of getdate()). My
> question : Is there a way to capture just the date without the time append
ed?
> For example, 04/04/2005. Question 2: How does SQL Server 2000 use indexe
s
> on this datetimestamp field? Would a clustered index on this field help?
> Almost all searching is done by the date field, whether it is searched by
day
> or a date range...Any better way than what is currently being done to help
> with speed ? Currently we have a clustered index on this column. The colu
mn
> currently contains approximately 12 million rows...
> Thanks for your input,
> Warren|||Thanks for all the replys...
I found out that the client application inserts the date stamp in the row of
the database. The colun is a dattime field, so it's not the getdate()) that
I thought it was..
Any more thoughts?
Thanks,
Warren
"CBretana" wrote:
> If you're really interested in speed, don;t use DateTime column use an
> integer or smallint.. and store the integer you get from Cast (getDate(
)
> as Integer) directly. This reduces the size of the data in the column fr
m
> 8bytes to 4 bytes (oor 2 bytes if you use smallint) By reducing the width
of
> the index, you will dramatically increase the number of entries you will b
e
> able to store on each IO Page of the index, and increase the performance
> using the index.
> NOTE: If you use smallints, then you need to subtract 32768 from the valu
> you get from Cast(getdate() as Integer) before stuffing it into the smalli
nt
> field, because smallint is SIGNED 2-byte integer, but smalldatetime uses
> UNSIGNED 2-byte integer..
> SmallDatetime goes from Integer value 0 represesnting 1 jan 1900, to 6553
6
> representing 6 June 2079... whereas smallint goes from -32768 to +32767...
> Using Regular datetime is no problem, because it uses SIGNED 4-byte Intege
r,
> with values from
> January 1, 1753 through December 31, (this way value 0 still represents 1
> Jan 1900... )
> If your queries against this table often use date as a range of dates...
> then a clustered index on this column will increase performance
> draamatically.
> "Warren" wrote:
>|||Then you need to
a) change the way the client write the data to strip off the time portion,
How is client writing to Database? using CLient constructed SQL,
Through a Stored Proc, etc.?
b) write an Insert/ update trigger on the database table that strips off the
time portion whenver client tries t owrite time into the table
In either case, To speed things up, same comments I made earlier about
datatypes still apply...
"Warren" wrote:
> Thanks for all the replys...
> I found out that the client application inserts the date stamp in the row
of
> the database. The colun is a dattime field, so it's not the getdate()) th
at
> I thought it was..
> Any more thoughts?
> Thanks,
> Warren
> "CBretana" wrote:
>sql

DateTime variable problem

Hi,
The followng snippet runs OK in SQL Query analyser when a literal date
'1/11/2006' is used for the first date comparision
When local variable @.StartDate is used instead it runs on forever (I think,
certainly an order of magnitude longer)
(I added the set dateformat dmy and switched to the numeric date format in
an effort to solve this.
Ideally I want to run with '1-Nov-2006' which for some reason runs faster
than the numeric version.)
Any ideas what I am doing wrong?
thanks
Bob
declare @.StartDate datetime
declare @.EndDate datetime
set dateformat dmy
set @.StartDate='1/11/2006'
set @.EndDate = '2/11/2006'
create Table #Temp (icp_id int)
insert into #Temp select distinct mh.icp_id as icp_id FROM routehistory rh
inner join metershistory mh
ON rh.id = mh.routehistory_id
inner join icps i on mh.icp_id=i.id
WHERE rh.type = 1 and i.company_id =1
and rh.read_date>= @.StartDate and rh.read_date < '2/11/2006' and
mh.cant_read_code is null
It will be because the optimiser is allowing for different values in the
variable. With the literal it knows to use the date index - with the variable
it is allowing for a large date range.
Look at the query plan and change the query (mayne a subquery for the date)
or give a hint or maybe include the other columns in the date index to make
it covering.
Maybe something like
FROM (select * from routehistory where read_date between @.StartDate and
@.EndDate) rh
.....
"Bob" wrote:

> Hi,
> The followng snippet runs OK in SQL Query analyser when a literal date
> '1/11/2006' is used for the first date comparision
> When local variable @.StartDate is used instead it runs on forever (I think,
> certainly an order of magnitude longer)
> (I added the set dateformat dmy and switched to the numeric date format in
> an effort to solve this.
> Ideally I want to run with '1-Nov-2006' which for some reason runs faster
> than the numeric version.)
> Any ideas what I am doing wrong?
> thanks
> Bob
> declare @.StartDate datetime
> declare @.EndDate datetime
> set dateformat dmy
> set @.StartDate='1/11/2006'
> set @.EndDate = '2/11/2006'
> create Table #Temp (icp_id int)
> insert into #Temp select distinct mh.icp_id as icp_id FROM routehistory rh
> inner join metershistory mh
> ON rh.id = mh.routehistory_id
> inner join icps i on mh.icp_id=i.id
> WHERE rh.type = 1 and i.company_id =1
> and rh.read_date>= @.StartDate and rh.read_date < '2/11/2006' and
> mh.cant_read_code is null
>
>
|||Bob
I have a couple of questions
1) Do you have an index (probably CI would be good choice) on read_date
column?
2) What happened if you change date format to YYYYMMDD and don't use SET
DATEFORMAT
"Bob" <bob@.nowhere.com> wrote in message
news:uRoiCglIHHA.4000@.TK2MSFTNGP06.phx.gbl...
> Hi,
> The followng snippet runs OK in SQL Query analyser when a literal date
> '1/11/2006' is used for the first date comparision
> When local variable @.StartDate is used instead it runs on forever (I
> think,
> certainly an order of magnitude longer)
> (I added the set dateformat dmy and switched to the numeric date format in
> an effort to solve this.
> Ideally I want to run with '1-Nov-2006' which for some reason runs faster
> than the numeric version.)
> Any ideas what I am doing wrong?
> thanks
> Bob
> declare @.StartDate datetime
> declare @.EndDate datetime
> set dateformat dmy
> set @.StartDate='1/11/2006'
> set @.EndDate = '2/11/2006'
> create Table #Temp (icp_id int)
> insert into #Temp select distinct mh.icp_id as icp_id FROM routehistory
> rh
> inner join metershistory mh
> ON rh.id = mh.routehistory_id
> inner join icps i on mh.icp_id=i.id
> WHERE rh.type = 1 and i.company_id =1
> and rh.read_date>= @.StartDate and rh.read_date < '2/11/2006' and
> mh.cant_read_code is null
>
|||Bob,
I think that you are being encountering what has become know as 'parameter
sniffing'.
You may wish to review these articles:
Stored Procedure -Parameter Sniffing
http://blogs.msdn.com/queryoptteam/archive/2006/03/31/565991.aspx
http://tinyurl.com/f9r2
http://sqlblogcasts.com/blogs/tonyrogerson/archive/2006/05/17/444.aspx
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
You can't help someone get up a hill without getting a little closer to the
top yourself.
- H. Norman Schwarzkopf
"Bob" <bob@.nowhere.com> wrote in message
news:uRoiCglIHHA.4000@.TK2MSFTNGP06.phx.gbl...
> Hi,
> The followng snippet runs OK in SQL Query analyser when a literal date
> '1/11/2006' is used for the first date comparision
> When local variable @.StartDate is used instead it runs on forever (I
> think,
> certainly an order of magnitude longer)
> (I added the set dateformat dmy and switched to the numeric date format in
> an effort to solve this.
> Ideally I want to run with '1-Nov-2006' which for some reason runs faster
> than the numeric version.)
> Any ideas what I am doing wrong?
> thanks
> Bob
> declare @.StartDate datetime
> declare @.EndDate datetime
> set dateformat dmy
> set @.StartDate='1/11/2006'
> set @.EndDate = '2/11/2006'
> create Table #Temp (icp_id int)
> insert into #Temp select distinct mh.icp_id as icp_id FROM routehistory
> rh
> inner join metershistory mh
> ON rh.id = mh.routehistory_id
> inner join icps i on mh.icp_id=i.id
> WHERE rh.type = 1 and i.company_id =1
> and rh.read_date>= @.StartDate and rh.read_date < '2/11/2006' and
> mh.cant_read_code is null
>
|||Hi All,
Thank you for your replies.
I won't pretend I understand Parameter sniffing.
What I have done is put the query into a sproc which was my end goal anyway
and I am tuning that up.
regards
Bob

DateTime variable problem

Hi,
The followng snippet runs OK in SQL Query analyser when a literal date
'1/11/2006' is used for the first date comparision
When local variable @.StartDate is used instead it runs on forever (I think,
certainly an order of magnitude longer)
(I added the set dateformat dmy and switched to the numeric date format in
an effort to solve this.
Ideally I want to run with '1-Nov-2006' which for some reason runs faster
than the numeric version.)
Any ideas what I am doing wrong?
thanks
Bob
declare @.StartDate datetime
declare @.EndDate datetime
set dateformat dmy
set @.StartDate='1/11/2006'
set @.EndDate = '2/11/2006'
create Table #Temp (icp_id int)
insert into #Temp select distinct mh.icp_id as icp_id FROM routehistory rh
inner join metershistory mh
ON rh.id = mh.routehistory_id
inner join icps i on mh.icp_id=i.id
WHERE rh.type = 1 and i.company_id =1
and rh.read_date>= @.StartDate and rh.read_date < '2/11/2006' and
mh.cant_read_code is nullIt will be because the optimiser is allowing for different values in the
variable. With the literal it knows to use the date index - with the variable
it is allowing for a large date range.
Look at the query plan and change the query (mayne a subquery for the date)
or give a hint or maybe include the other columns in the date index to make
it covering.
Maybe something like
FROM (select * from routehistory where read_date between @.StartDate and
@.EndDate) rh
....
"Bob" wrote:
> Hi,
> The followng snippet runs OK in SQL Query analyser when a literal date
> '1/11/2006' is used for the first date comparision
> When local variable @.StartDate is used instead it runs on forever (I think,
> certainly an order of magnitude longer)
> (I added the set dateformat dmy and switched to the numeric date format in
> an effort to solve this.
> Ideally I want to run with '1-Nov-2006' which for some reason runs faster
> than the numeric version.)
> Any ideas what I am doing wrong?
> thanks
> Bob
> declare @.StartDate datetime
> declare @.EndDate datetime
> set dateformat dmy
> set @.StartDate='1/11/2006'
> set @.EndDate = '2/11/2006'
> create Table #Temp (icp_id int)
> insert into #Temp select distinct mh.icp_id as icp_id FROM routehistory rh
> inner join metershistory mh
> ON rh.id = mh.routehistory_id
> inner join icps i on mh.icp_id=i.id
> WHERE rh.type = 1 and i.company_id =1
> and rh.read_date>= @.StartDate and rh.read_date < '2/11/2006' and
> mh.cant_read_code is null
>
>|||Bob
I have a couple of questions
1) Do you have an index (probably CI would be good choice) on read_date
column?
2) What happened if you change date format to YYYYMMDD and don't use SET
DATEFORMAT
"Bob" <bob@.nowhere.com> wrote in message
news:uRoiCglIHHA.4000@.TK2MSFTNGP06.phx.gbl...
> Hi,
> The followng snippet runs OK in SQL Query analyser when a literal date
> '1/11/2006' is used for the first date comparision
> When local variable @.StartDate is used instead it runs on forever (I
> think,
> certainly an order of magnitude longer)
> (I added the set dateformat dmy and switched to the numeric date format in
> an effort to solve this.
> Ideally I want to run with '1-Nov-2006' which for some reason runs faster
> than the numeric version.)
> Any ideas what I am doing wrong?
> thanks
> Bob
> declare @.StartDate datetime
> declare @.EndDate datetime
> set dateformat dmy
> set @.StartDate='1/11/2006'
> set @.EndDate = '2/11/2006'
> create Table #Temp (icp_id int)
> insert into #Temp select distinct mh.icp_id as icp_id FROM routehistory
> rh
> inner join metershistory mh
> ON rh.id = mh.routehistory_id
> inner join icps i on mh.icp_id=i.id
> WHERE rh.type = 1 and i.company_id =1
> and rh.read_date>= @.StartDate and rh.read_date < '2/11/2006' and
> mh.cant_read_code is null
>|||Bob,
I think that you are being encountering what has become know as 'parameter
sniffing'.
You may wish to review these articles:
Stored Procedure -Parameter Sniffing
http://blogs.msdn.com/queryoptteam/archive/2006/03/31/565991.aspx
http://tinyurl.com/f9r2
http://sqlblogcasts.com/blogs/tonyrogerson/archive/2006/05/17/444.aspx
--
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
You can't help someone get up a hill without getting a little closer to the
top yourself.
- H. Norman Schwarzkopf
"Bob" <bob@.nowhere.com> wrote in message
news:uRoiCglIHHA.4000@.TK2MSFTNGP06.phx.gbl...
> Hi,
> The followng snippet runs OK in SQL Query analyser when a literal date
> '1/11/2006' is used for the first date comparision
> When local variable @.StartDate is used instead it runs on forever (I
> think,
> certainly an order of magnitude longer)
> (I added the set dateformat dmy and switched to the numeric date format in
> an effort to solve this.
> Ideally I want to run with '1-Nov-2006' which for some reason runs faster
> than the numeric version.)
> Any ideas what I am doing wrong?
> thanks
> Bob
> declare @.StartDate datetime
> declare @.EndDate datetime
> set dateformat dmy
> set @.StartDate='1/11/2006'
> set @.EndDate = '2/11/2006'
> create Table #Temp (icp_id int)
> insert into #Temp select distinct mh.icp_id as icp_id FROM routehistory
> rh
> inner join metershistory mh
> ON rh.id = mh.routehistory_id
> inner join icps i on mh.icp_id=i.id
> WHERE rh.type = 1 and i.company_id =1
> and rh.read_date>= @.StartDate and rh.read_date < '2/11/2006' and
> mh.cant_read_code is null
>|||Hi All,
Thank you for your replies.
I won't pretend I understand Parameter sniffing.
What I have done is put the query into a sproc which was my end goal anyway
and I am tuning that up.
regards
Bob

DateTime variable problem

Hi,
The followng snippet runs OK in SQL Query analyser when a literal date
'1/11/2006' is used for the first date comparision
When local variable @.StartDate is used instead it runs on forever (I think,
certainly an order of magnitude longer)
(I added the set dateformat dmy and switched to the numeric date format in
an effort to solve this.
Ideally I want to run with '1-Nov-2006' which for some reason runs faster
than the numeric version.)
Any ideas what I am doing wrong?
thanks
Bob
declare @.StartDate datetime
declare @.EndDate datetime
set dateformat dmy
set @.StartDate='1/11/2006'
set @.EndDate = '2/11/2006'
create Table #Temp (icp_id int)
insert into #Temp select distinct mh.icp_id as icp_id FROM routehistory rh
inner join metershistory mh
ON rh.id = mh.routehistory_id
inner join icps i on mh.icp_id=i.id
WHERE rh.type = 1 and i.company_id =1
and rh.read_date>= @.StartDate and rh.read_date < '2/11/2006' and
mh.cant_read_code is nullIt will be because the optimiser is allowing for different values in the
variable. With the literal it knows to use the date index - with the variabl
e
it is allowing for a large date range.
Look at the query plan and change the query (mayne a subquery for the date)
or give a hint or maybe include the other columns in the date index to make
it covering.
Maybe something like
FROM (select * from routehistory where read_date between @.StartDate and
@.EndDate) rh
....
"Bob" wrote:

> Hi,
> The followng snippet runs OK in SQL Query analyser when a literal date
> '1/11/2006' is used for the first date comparision
> When local variable @.StartDate is used instead it runs on forever (I think
,
> certainly an order of magnitude longer)
> (I added the set dateformat dmy and switched to the numeric date format in
> an effort to solve this.
> Ideally I want to run with '1-Nov-2006' which for some reason runs faster
> than the numeric version.)
> Any ideas what I am doing wrong?
> thanks
> Bob
> declare @.StartDate datetime
> declare @.EndDate datetime
> set dateformat dmy
> set @.StartDate='1/11/2006'
> set @.EndDate = '2/11/2006'
> create Table #Temp (icp_id int)
> insert into #Temp select distinct mh.icp_id as icp_id FROM routehistory
rh
> inner join metershistory mh
> ON rh.id = mh.routehistory_id
> inner join icps i on mh.icp_id=i.id
> WHERE rh.type = 1 and i.company_id =1
> and rh.read_date>= @.StartDate and rh.read_date < '2/11/2006' and
> mh.cant_read_code is null
>
>|||Bob
I have a couple of questions
1) Do you have an index (probably CI would be good choice) on read_date
column?
2) What happened if you change date format to YYYYMMDD and don't use SET
DATEFORMAT
"Bob" <bob@.nowhere.com> wrote in message
news:uRoiCglIHHA.4000@.TK2MSFTNGP06.phx.gbl...
> Hi,
> The followng snippet runs OK in SQL Query analyser when a literal date
> '1/11/2006' is used for the first date comparision
> When local variable @.StartDate is used instead it runs on forever (I
> think,
> certainly an order of magnitude longer)
> (I added the set dateformat dmy and switched to the numeric date format in
> an effort to solve this.
> Ideally I want to run with '1-Nov-2006' which for some reason runs faster
> than the numeric version.)
> Any ideas what I am doing wrong?
> thanks
> Bob
> declare @.StartDate datetime
> declare @.EndDate datetime
> set dateformat dmy
> set @.StartDate='1/11/2006'
> set @.EndDate = '2/11/2006'
> create Table #Temp (icp_id int)
> insert into #Temp select distinct mh.icp_id as icp_id FROM routehistory
> rh
> inner join metershistory mh
> ON rh.id = mh.routehistory_id
> inner join icps i on mh.icp_id=i.id
> WHERE rh.type = 1 and i.company_id =1
> and rh.read_date>= @.StartDate and rh.read_date < '2/11/2006' and
> mh.cant_read_code is null
>|||Bob,
I think that you are being encountering what has become know as 'parameter
sniffing'.
You may wish to review these articles:
Stored Procedure -Parameter Sniffing
http://blogs.msdn.com/queryoptteam/.../31/565991.aspx
http://tinyurl.com/f9r2
http://sqlblogcasts.com/blogs/tonyr.../05/17/444.aspx
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
You can't help someone get up a hill without getting a little closer to the
top yourself.
- H. Norman Schwarzkopf
"Bob" <bob@.nowhere.com> wrote in message
news:uRoiCglIHHA.4000@.TK2MSFTNGP06.phx.gbl...
> Hi,
> The followng snippet runs OK in SQL Query analyser when a literal date
> '1/11/2006' is used for the first date comparision
> When local variable @.StartDate is used instead it runs on forever (I
> think,
> certainly an order of magnitude longer)
> (I added the set dateformat dmy and switched to the numeric date format in
> an effort to solve this.
> Ideally I want to run with '1-Nov-2006' which for some reason runs faster
> than the numeric version.)
> Any ideas what I am doing wrong?
> thanks
> Bob
> declare @.StartDate datetime
> declare @.EndDate datetime
> set dateformat dmy
> set @.StartDate='1/11/2006'
> set @.EndDate = '2/11/2006'
> create Table #Temp (icp_id int)
> insert into #Temp select distinct mh.icp_id as icp_id FROM routehistory
> rh
> inner join metershistory mh
> ON rh.id = mh.routehistory_id
> inner join icps i on mh.icp_id=i.id
> WHERE rh.type = 1 and i.company_id =1
> and rh.read_date>= @.StartDate and rh.read_date < '2/11/2006' and
> mh.cant_read_code is null
>sql

DateTime Values in SQL Express ASPNETDB.MDF

greets again folks,

The values LastLoginDate and LastActivityDate in my SQl Express membership dBase are always off.

The date is usually correct but the time is always hours off.

Is there some way to get the time part of the DateTime to be correct?

Do I have to write code to set the time when the user logs in?

Thanks a mil!

It sounds as if GetUtcDate() is being called instead of GetDate. GetUTCDate records the UTC or GMT date time whereas GetDate() get the local date time.

|||

hypercode:

greets again folks,

The values LastLoginDate and LastActivityDate in my SQl Express membership dBase are always off.

The date is usually correct but the time is always hours off.

Is there some way to get the time part of the DateTime to be correct?

Do I have to write code to set the time when the user logs in?

Thanks a mil!

check database coumn type ... is it set to DateTime ....

|||

Kamrul,

Although unlikely, the column does not have to be a DateTime to have GetDate assigned to it. E.g.SELECTCONVERT(VARCHAR(20),GetDate(), 113) returned "19 Apr 2007 17:07:06". but could have inserted the valud into a CHAR(20) column.

|||

The date is OFF in the ASPNETDB itself.

Beoroe I write any code to retireve the values, they are already in the dBase off to begin with.

Is there some way to tell the dBase to record the correct times?

|||

Look in the table definition, do the collumns have the default property change the GetUtcDate() to GetDate(). Do the same in the stored procedures and all date/time from then will be in local rather than universal time.

Incidentally was the time an exact number of hours off from the server time?

|||

" Look in the table definition, do the collumns have the default property change the GetUtcDate() to GetDate(). Do the same in the stored procedures and all date/time from then will be in local rather than universal time. "

I just looked in the table definition for all of the columns which contain datetime date types. I don't see GetUtcDate or GetDate() anywhere in the table definition. Where should these values be displayed?

|||If the data is not being set by a default property, look in the stored procedures for them.|||

Hi Hypercode,

Actually,the datetime value is saved as UTC format in system or database. When there's a request from a user, the server will translate the time into local time which depends on the server's location and response the user's request. So pls be sure that the settings of the timezone on your server is correct ( or just as you want).

If the problem still exists, you have to translate the time manually.Here's the UDF that you might be interested in looking into

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=28712

Hope it helps.

Thanks

|||

Thanks to you guys for pitchin in!

I still didn't get her straightened out yet. Been busy with other stuff (on the same project). I'll be getiing this straightened out though when I get a chance.

DateTime validation throgh sql query

hai friends,
how can i made validation of date time through sql query?

Swati

Check out the SQL Function: IsDate()|||Validation is best done from front end technology rather than make a round trip to the DB just to validate a date field.