Showing posts with label via. Show all posts
Showing posts with label via. Show all posts

Thursday, March 29, 2012

DB backup to another server

How do I configure SQL Server Agent and my Database Maintenance Plans to
enable sending backups to another server via UNC pathnames and restoring
from the same location? Backing up locally and copying files to the other
server doesn't make good use of the functionality of deleting backups older
than a certain number of days.
I've already created a domain admin user, shared the destination folder to
this user will full permissions, set SQL Server Agent to login under the
context of this domain admin user, but my backups still won't go to that
remote server.This is a multi-part message in MIME format.
--=_NextPart_000_0525_01C3B825.106A5290
Content-Type: text/plain;
charset="Windows-1252"
Content-Transfer-Encoding: 7bit
Have you also configured SQL Server itself to run under that domain account?
--
Tom
---
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinnaclepublishing.com/sql
"David Morrison" <me@.nospam.com> wrote in message
news:u$XDJ5EuDHA.424@.TK2MSFTNGP11.phx.gbl...
How do I configure SQL Server Agent and my Database Maintenance Plans to
enable sending backups to another server via UNC pathnames and restoring
from the same location? Backing up locally and copying files to the other
server doesn't make good use of the functionality of deleting backups older
than a certain number of days.
I've already created a domain admin user, shared the destination folder to
this user will full permissions, set SQL Server Agent to login under the
context of this domain admin user, but my backups still won't go to that
remote server.
--=_NextPart_000_0525_01C3B825.106A5290
Content-Type: text/html;
charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
&

Have you also configured SQL Server =itself to run under that domain account?
-- Tom
---T=homas A. Moreau, BSc, PhD, MCSE, MCDBASQL Server MVPColumnist, SQL =Server ProfessionalToronto, ON Canadahttp://www.pinnaclepublishing.com/sql">www.pinnaclepublishing.com=/sql
"David Morrison" wrote in message news:u$XDJ5EuDHA.424@.T=K2MSFTNGP11.phx.gbl...How do I configure SQL Server Agent and my Database Maintenance Plans =toenable sending backups to another server via UNC pathnames and =restoringfrom the same location? Backing up locally and copying files to the =otherserver doesn't make good use of the functionality of deleting backups =olderthan a certain number of days.I've already created a domain admin user, =shared the destination folder tothis user will full permissions, set SQL =Server Agent to login under thecontext of this domain admin user, but my =backups still won't go to thatremote server.

--=_NextPart_000_0525_01C3B825.106A5290--|||This is a multi-part message in MIME format.
--=_NextPart_000_0014_01C3B816.F2397930
Content-Type: text/plain;
charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
No. Is that necessary?
"Tom Moreau" <tom@.dont.spam.me.cips.ca> wrote in message =news:%23T3787EuDHA.2448@.TK2MSFTNGP12.phx.gbl...
Have you also configured SQL Server itself to run under that domain =account?
-- Tom
---
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinnaclepublishing.com/sql
"David Morrison" <me@.nospam.com> wrote in message =news:u$XDJ5EuDHA.424@.TK2MSFTNGP11.phx.gbl...
How do I configure SQL Server Agent and my Database Maintenance Plans =to
enable sending backups to another server via UNC pathnames and =restoring
from the same location? Backing up locally and copying files to the =other
server doesn't make good use of the functionality of deleting backups =older
than a certain number of days.
I've already created a domain admin user, shared the destination =folder to
this user will full permissions, set SQL Server Agent to login under =the
context of this domain admin user, but my backups still won't go to =that
remote server.
--=_NextPart_000_0014_01C3B816.F2397930
Content-Type: text/html;
charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
&

No. Is that =necessary?
"Tom Moreau" = wrote in message news:%23T3787EuDHA.=2448@.TK2MSFTNGP12.phx.gbl...
Have you also configured SQL Server =itself to run under that domain account?
-- Tom

=---T=homas A. Moreau, BSc, PhD, MCSE, MCDBASQL Server MVPColumnist, SQL =Server ProfessionalToronto, ON Canadahttp://www.pinnaclepublishing.com/sql">www.pinnaclepublishing.com=/sql


"David Morrison" wrote in message news:u$XDJ5EuDHA.424@.T=K2MSFTNGP11.phx.gbl...How do I configure SQL Server Agent and my Database Maintenance Plans =toenable sending backups to another server via UNC pathnames and =restoringfrom the same location? Backing up locally and copying files to the otherserver doesn't make good use of the functionality of deleting =backups olderthan a certain number of days.I've already created a =domain admin user, shared the destination folder tothis user will full permissions, set SQL Server Agent to login under thecontext of =this domain admin user, but my backups still won't go to thatremote server.

--=_NextPart_000_0014_01C3B816.F2397930--|||This is a multi-part message in MIME format.
--=_NextPart_000_0022_01C3B81B.15455940
Content-Type: text/plain;
charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
That was it! You made my day. Thanks!
"Tom Moreau" <tom@.dont.spam.me.cips.ca> wrote in message =news:%23T3787EuDHA.2448@.TK2MSFTNGP12.phx.gbl...
Have you also configured SQL Server itself to run under that domain =account?
-- Tom
---
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinnaclepublishing.com/sql
"David Morrison" <me@.nospam.com> wrote in message =news:u$XDJ5EuDHA.424@.TK2MSFTNGP11.phx.gbl...
How do I configure SQL Server Agent and my Database Maintenance Plans =to
enable sending backups to another server via UNC pathnames and =restoring
from the same location? Backing up locally and copying files to the =other
server doesn't make good use of the functionality of deleting backups =older
than a certain number of days.
I've already created a domain admin user, shared the destination =folder to
this user will full permissions, set SQL Server Agent to login under =the
context of this domain admin user, but my backups still won't go to =that
remote server.
--=_NextPart_000_0022_01C3B81B.15455940
Content-Type: text/html;
charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
&

That was it! You made my =day. Thanks!
"Tom Moreau" = wrote in message news:%23T3787EuDHA.=2448@.TK2MSFTNGP12.phx.gbl...
Have you also configured SQL Server =itself to run under that domain account?
-- Tom

=---T=homas A. Moreau, BSc, PhD, MCSE, MCDBASQL Server MVPColumnist, SQL =Server ProfessionalToronto, ON Canadahttp://www.pinnaclepublishing.com/sql">www.pinnaclepublishing.com=/sql


"David Morrison" wrote in message news:u$XDJ5EuDHA.424@.T=K2MSFTNGP11.phx.gbl...How do I configure SQL Server Agent and my Database Maintenance Plans =toenable sending backups to another server via UNC pathnames and =restoringfrom the same location? Backing up locally and copying files to the otherserver doesn't make good use of the functionality of deleting =backups olderthan a certain number of days.I've already created a =domain admin user, shared the destination folder tothis user will full permissions, set SQL Server Agent to login under thecontext of =this domain admin user, but my backups still won't go to thatremote server.

--=_NextPart_000_0022_01C3B81B.15455940--|||I have the same problem. SQL Server runs using an NT account, this account has permissions on the backup server and while logged into the first server using this same NT account I'm able to map a drive to the backup server. But when I go through Enterprise Manager and look for this destination via the SQL Server Backup window, I don't find it. Please advise
-- David Morrison wrote: --
No. Is that necessary
"Tom Moreau" <tom@.dont.spam.me.cips.ca> wrote in message news:%23T3787EuDHA.2448@.TK2MSFTNGP12.phx.gbl..
Have you also configured SQL Server itself to run under that domain account
--
To
---
Thomas A. Moreau, BSc, PhD, MCSE, MCDB
SQL Server MV
Columnist, SQL Server Professiona
Toronto, ON Canad
www.pinnaclepublishing.com/sq
"David Morrison" <me@.nospam.com> wrote in message news:u$XDJ5EuDHA.424@.TK2MSFTNGP11.phx.gbl..
How do I configure SQL Server Agent and my Database Maintenance Plans t
enable sending backups to another server via UNC pathnames and restorin
from the same location? Backing up locally and copying files to the othe
server doesn't make good use of the functionality of deleting backups olde
than a certain number of days
I've already created a domain admin user, shared the destination folder t
this user will full permissions, set SQL Server Agent to login under th
context of this domain admin user, but my backups still won't go to tha
remote server|||This is a multi-part message in MIME format.
--=_NextPart_000_00AA_01C3B84F.60E51960
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 7bit
Use the full UNC name for the backup destination. You cannot map to a drive
letter.
--
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinnaclepublishing.com/sql
.
"Simi Rao" <anonymous@.discussions.microsoft.com> wrote in message
news:21C576AF-AB76-49E8-899D-8058242FE3F2@.microsoft.com...
I have the same problem. SQL Server runs using an NT account, this account
has permissions on the backup server and while logged into the first server
using this same NT account I'm able to map a drive to the backup server.
But when I go through Enterprise Manager and look for this destination via
the SQL Server Backup window, I don't find it. Please advise.
-- David Morrison wrote: --
No. Is that necessary?
"Tom Moreau" <tom@.dont.spam.me.cips.ca> wrote in message
news:%23T3787EuDHA.2448@.TK2MSFTNGP12.phx.gbl...
Have you also configured SQL Server itself to run under that domain
account?
--
Tom
---
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinnaclepublishing.com/sql
"David Morrison" <me@.nospam.com> wrote in message
news:u$XDJ5EuDHA.424@.TK2MSFTNGP11.phx.gbl...
How do I configure SQL Server Agent and my Database Maintenance Plans
to
enable sending backups to another server via UNC pathnames and
restoring
from the same location? Backing up locally and copying files to the
other
server doesn't make good use of the functionality of deleting backups
older
than a certain number of days.
I've already created a domain admin user, shared the destination
folder to
this user will full permissions, set SQL Server Agent to login under
the
context of this domain admin user, but my backups still won't go to
that
remote server
--=_NextPart_000_00AA_01C3B84F.60E51960
Content-Type: text/html;
charset="Utf-8"
Content-Transfer-Encoding: quoted-printable
=EF=BB=BF<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
&

Use the full UNC name for the backup destination. You cannot map to a drive letter.
-- Tom
----Thomas A. =Moreau, BSc, PhD, MCSE, MCDBASQL Server MVPColumnist, SQL Server ProfessionalToronto, ON Canadahttp://www.pinnaclepublishing.com/sql">www.pinnaclepublishing.com=/sql.
"Simi Rao" wrote in message news:21C=576AF-AB76-49E8-899D-8058242FE3F2@.microsoft.com...I have the same problem. SQL Server runs using an NT account, this =account has permissions on the backup server and while logged into the first =server using this same NT account I'm able to map a drive to the backup =server. But when I go through Enterprise Manager and look for this destination =via the SQL Server Backup window, I don't find it. Please advise. -- =David Morrison wrote: -- = No. Is that necessary? ="Tom Moreau" = wrote in message news:%23T3787EuDHA.=2448@.TK2MSFTNGP12.phx.gbl... =Have you also configured SQL Server itself to run under that domain account? = -- Tom = --- = Thomas A. Moreau, BSc, PhD, MCSE, =MCDBA SQL Server MVP Columnist, SQL =Server Professional Toronto, ON Canada http://www.pinnaclepublishing.com/sql">www.pinnaclepublishing.com=/sql ="David Morrison" =wrote in message news:u$XDJ5EuDHA.424@.T=K2MSFTNGP11.phx.gbl... How do I configure SQL Server Agent and my Database Maintenance Plans to enable sending backups to =another server via UNC pathnames and =restoring from the same location? Backing up locally and copying files to =the other server doesn't make good =use of the functionality of deleting backups older than a certain number of days. = I've already created a domain admin user, shared the destination folder to this user will full =permissions, set SQL Server Agent to login under =the context of this domain admin user, but my backups still won't go to that remote server

--=_NextPart_000_00AA_01C3B84F.60E51960--|||I'm having a similar problem. Does SQL Server itself have
to run under the domain account? Is this the MSSQLSERVER
service? I have the permissions on the remote folder set
for the domain admin. The SQL job for the maintenance
plan is owned by the domain admin. The SQL Agent service
is started under the domain admin. Still, the backups are
failing and the log indicates that access is denied in
creating the backup and it appears that 'sa' is invoking
the job.
>--Original Message--
>No. Is that necessary?
> "Tom Moreau" <tom@.dont.spam.me.cips.ca> wrote in
message news:%23T3787EuDHA.2448@.TK2MSFTNGP12.phx.gbl...
> Have you also configured SQL Server itself to run under
that domain account?
> --
> Tom
> ---
--
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada
> www.pinnaclepublishing.com/sql
>
> "David Morrison" <me@.nospam.com> wrote in message
news:u$XDJ5EuDHA.424@.TK2MSFTNGP11.phx.gbl...
> How do I configure SQL Server Agent and my Database
Maintenance Plans to
> enable sending backups to another server via UNC
pathnames and restoring
> from the same location? Backing up locally and copying
files to the other
> server doesn't make good use of the functionality of
deleting backups older
> than a certain number of days.
> I've already created a domain admin user, shared the
destination folder to
> this user will full permissions, set SQL Server Agent
to login under the
> context of this domain admin user, but my backups still
won't go to that
> remote server.
>|||This is a multi-part message in MIME format.
--=_NextPart_000_001C_01C3C328.296D6850
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
The SQL Server service has to run under a domain account to do what you
want. That said, you should not use the domain admin account. That's way
to much authority. Create a separate account that can run as a service and
use it.
--
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinnaclepublishing.com/sql
.
<anonymous@.discussions.microsoft.com> wrote in message
news:108a01c3c33e$5b4bd170$3101280a@.phx.gbl...
I'm having a similar problem. Does SQL Server itself have
to run under the domain account? Is this the MSSQLSERVER
service? I have the permissions on the remote folder set
for the domain admin. The SQL job for the maintenance
plan is owned by the domain admin. The SQL Agent service
is started under the domain admin. Still, the backups are
failing and the log indicates that access is denied in
creating the backup and it appears that 'sa' is invoking
the job.
>--Original Message--
>No. Is that necessary?
> "Tom Moreau" <tom@.dont.spam.me.cips.ca> wrote in
message news:%23T3787EuDHA.2448@.TK2MSFTNGP12.phx.gbl...
> Have you also configured SQL Server itself to run under
that domain account?
> --
> Tom
> ---
--
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada
> www.pinnaclepublishing.com/sql
>
> "David Morrison" <me@.nospam.com> wrote in message
news:u$XDJ5EuDHA.424@.TK2MSFTNGP11.phx.gbl...
> How do I configure SQL Server Agent and my Database
Maintenance Plans to
> enable sending backups to another server via UNC
pathnames and restoring
> from the same location? Backing up locally and copying
files to the other
> server doesn't make good use of the functionality of
deleting backups older
> than a certain number of days.
> I've already created a domain admin user, shared the
destination folder to
> this user will full permissions, set SQL Server Agent
to login under the
> context of this domain admin user, but my backups still
won't go to that
> remote server.
>
--=_NextPart_000_001C_01C3C328.296D6850
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
&

The SQL Server service has to run =under a domain account to do what you want. That said, you should not use the =domain admin account. That's way to much authority. Create a =separate account that can run as a service and use it.
-- Tom
----Thomas A. =Moreau, BSc, PhD, MCSE, MCDBASQL Server MVPColumnist, SQL Server ProfessionalToronto, ON Canadahttp://www.pinnaclepublishing.com/sql">www.pinnaclepublishing.com=/sql.
wrote in message news:108a01c3c33e$5b=4bd170$3101280a@.phx.gbl...I'm having a similar problem. Does SQL Server itself have to run =under the domain account? Is this the MSSQLSERVER service? I have the permissions on the remote folder set for the domain admin. The =SQL job for the maintenance plan is owned by the domain admin. The SQL =Agent service is started under the domain admin. Still, the backups =are failing and the log indicates that access is denied in creating =the backup and it appears that 'sa' is invoking the job.>--Original Message-->No. Is that necessary?> "Tom Moreau" = wrote in message news:%23T3787EuDHA.=2448@.TK2MSFTNGP12.phx.gbl...> Have you also configured SQL Server itself to run under that domain account?>> -- > =Tom>> -----&g=t; Thomas A. Moreau, BSc, PhD, MCSE, MCDBA> SQL Server MVP> Columnist, SQL Server Professional> =Toronto, ON Canada>http://www.pinnaclepublishing.com/sql">www.pinnaclepublishing.com=/sql>>> "David Morrison" wrote in message news:u$XDJ5EuDHA.424@.T=K2MSFTNGP11.phx.gbl...> How do I configure SQL Server Agent and my Database Maintenance =Plans to> enable sending backups to another server via UNC =pathnames and restoring> from the same location? Backing up =locally and copying files to the other> server doesn't make good =use of the functionality of deleting backups older> than a certain =number of days.>> I've already created a domain admin user, =shared the destination folder to> this user will full =permissions, set SQL Server Agent to login under the> context of this =domain admin user, but my backups still won't go to that> =remote server.>>

--=_NextPart_000_001C_01C3C328.296D6850--

Wednesday, March 21, 2012

Datetime problems

Hallo,

I have two different problems with datetime columns and MSSQL:

1)
Connecting via PHP 4.4.4 (Linux/Apache/freetds/mssql_connect) to MSSQL I receive a wrong month when selecting a datetime column: 00 is January and 11 December. E.g.:
select getdate()
2007-00-04 19:14:48

Selecting "convert(varchar(30), getdate(), 120)" returns the correct date:
2007-01-04 19:14:48
But I need that getdate() or selecting datetime columns without convert works correct, too.

2)
Connecting via PHP 4.4.4 (Windows Server 2003/ISAPI/MS-IIS 6.0/mssql_connect) to MSSQL and updating a datetime column it interchanges month and day, e.g.
update [mytable] set mydatetimecolumn="2007-01-04 19:14:48"
will set the datetime column to "2007-04-01 19:14:48".
I solved the problem with a "set dateformat ymd" before updating but I would prefer a permanent solution without the set command.

Thanks for any help1) This looks like a driver problem to me. Since converting the date to a string on SQL Server gives you the right date, nothing is wrong there. See if there are any know problems with the drivers and make sure you have the latest version.

2) De format in which the dates are handled on SQL server is determined in your server settings. Sending a string and hoping it will be alright is never a good idea (moving the databases to another server can get you in a lot of trouble that way). Always tell SQL Server in which format you are supplying the date by using the convert-function:
UPDATE[mytable]
SET mydatetimecolumn= CONVERT(DATETIME, '2007-01-04 19:14:48', 120)|||Thank you very much for your reply, Lexiflex.

2)
I need it in generic scripts where I don't know which column is a datetime field. And I don't really want to detect which type each column has before updating.
I thought that this format (ODBC canonical) cannot be misunderstood and that every SQL DBMS would interprete it correctly.
The strange thing is that I receive datetime columns in ODBC canonical ("YYYY-MM-DD HH:MM:SS") when selecting them.
Is there any datetime format which MSSQL can interprete without a convert command ? I read somewhere that "YYYYMMDD HH:MM:SS" could be. But I didn't found it in the CAST/CONVERT table. And I don't know how to convince MSSQL to return the datetime columns in this format by default.

Any suggestions ?|||The format "YYYYMMDD HH:MM: SS" seems to work and I sometimes use it when I need to use a date quickly in a development area.

I don't know how to convince MSSQL to return the datetime columns in this format by default.
You have to understand that sending a date is different from receiving one. When SQL Server returns a date it does so in a, to me, unknown way and it is the client application that formats it before presenting it to you (e.g. you can tell Query Analyzer how to show dates). So if you want to present it in a certain format you have to look a the settings of your client application.|||1)
The problem is still unsolved.
Does anybody have the same problem?
The problem seems to come from the PHP mssql support.
(I have some bigger problems with the odbc driver, too. So I cannot use it.)

Using odbc- or mssql- connect return different results
when selecting getdate() although both should use freetds i think:
PHP using odbc_connect (correct)
2007-02-05 16:25:25
PHP using mssql_connect (wrong)
2007-01-05 16:25:25

TSQL (freetds) tells me the correct date, too:
1> select getdate()
2> go
2007-02-05 16:25:25

Here more details of the system:
-----------
Apache/1.3.33 (Debian GNU/Linux)
PHP/4.4.4
mssql Library version 7.0
mssql.compatability_mode off
mssql.datetimeconvert off
ODBC library unixODBC
freetds v0.62.4 (TDS version: 8.0, unixodbc: yes)

Microsoft SQL Server 2000 - 8.00.2039 (Intel X86)
Desktop Engine on Windows NT 5.2 (Build 3790: Service Pack 1)

PLEASE HELP!|||1)
Finally we solved the problem with compiling FreeTDS using --enable-msdblib.

See also:
http://bugs.php.net/bug.php?id=22060
http://bugs.php.net/bug.php?id=32022

Wednesday, March 7, 2012

Datetime and other stuff

Overview. Machine data is fed into DOWNTIMELOG via a Cimplicity. I do not have the ability to change the way that it goes in. It contains the time that a machine has stopped and where the stoppage has occurred. Via a web page I want to give the operator the amount of time the machine stopped. From that they will provide some more detail. As they enter time, I need to subtract what they entered from the total (DOWNTIMELOG). That is the reason I created ENTERED_TIME. [PDNTOTAL_TEMP_VAL0] hold the total time for each stoppage, [TOTTIME] is intended to hold the value that has been accounted for. [DWNCATEGORY_TEMP_VAL0] holds the category and matches up with [DWNCATEGORY]. Also, I need to match Date and Shift. The problem is that DOWNTIMELOG does not capture shift. However, 1st shift occurs between 700 and 1500, 2nd shift occurs between 1500 and 2300, 3rd shift occurs between 2300 and 700. 3rd shift presents a problem as it occurs across 2 dates. Could someone please help me with a query that provides the net between the two tables that is matched by date, shift and category?
CREATE TABLE [dbo].[DOWNTIMELOG] (
[timestamp] [datetime] NOT NULL ,
[DWNTIMESTAMP_VAL0] [varchar] (25) NULL ,
[UPTIMESTAMP_VAL0] [varchar] (25) NULL ,
[PDNHOUR_VAL0] [int] NULL ,
[PDNMIN_VAL0] [int] NULL ,
[PDNSEC_VAL0] [int] NULL ,
[PDNTOTAL_TEMP_VAL0] [int] NULL ,
[DWNMSG_TEMP_VAL0] [int] NULL ,
[DWNCATEGORY_TEMP_VAL0] [varchar] (50) NULL

CREATE TABLE [dbo].[ENTERED_TIME] (
[REC_ID] [int] IDENTITY (1, 1) NOT NULL ,
[DWNCATEGORY] [varchar] (50) NULL ,
[DWNMSG] [int] NULL ,
[ENTRYDATE] [smalldatetime] NULL ,
[SHIFT] [int] NULL ,
[TOTTIME] [int] NULLWould someone please review this approach to getting a shift from a timestamp AND changing the date to the following when the Hour is greater than 23:00? I keep getting nulls for hours outside 7 and 14.
SELECT [timestamp] AS thaTimeStamp, (CASE WHEN DATEPART(hh, [timestamp])
= 23 THEN CAST(FLOOR(CAST(DATEADD(d, 1, [timestamp]) AS Float(53))) AS DateTime) ELSE CAST(FLOOR(CAST([timestamp] AS Float(53)))
AS DateTime) END) AS thaDate, (CASE WHEN DATEPART(hh, [timestamp]) > 6 AND DATEPART(hh, [timestamp]) < 15 THEN 1 WHEN DATEPART(hh,
[timestamp]) > 14 AND DATEPART(hh, [timestamp]) < 23 THEN 2 WHEN CAST(DATEPART(hh, [timestamp]) AS INT) > 23 AND CAST(DATEPART(hh,
[timestamp]) AS INT) < 7 THEN 3 END) AS thaShift, DATEPART(hh, [timestamp]) AS thaOutPut
FROM DOWNTIMELOG
WHERE ([timestamp] >= CONVERT(DATETIME, '2005-12-10 00:00:00', 102))

Out put
thaTimeStamp thaDate thaShift thaOutPut
12/10/2005 6:29:05 AM 12/10/2005 <NULL> 6
12/10/2005 7:18:03 AM 12/10/2005 1 7
12/10/2005 7:22:07 AM 12/10/2005 1 7
12/10/2005 7:24:01 AM 12/10/2005 1 7
12/10/2005 7:24:39 AM 12/10/2005 1 7
12/12/2005 6:06:46 AM 12/12/2005 <NULL> 6
12/12/2005 6:19:20 AM 12/12/2005 <NULL> 6
12/12/2005 6:25:28 AM 12/12/2005 <NULL> 6
12/12/2005 7:12:41 AM 12/12/2005 1 7|||SELECT [timestamp] AS thaTimeStamp
, (CASE
WHEN DATEPART(hh, [timestamp]) = 23 THEN CAST(FLOOR(CAST(DATEADD(d, 1, [timestamp]) AS Float(53))) AS DateTime)
ELSE CAST(FLOOR(CAST([timestamp] AS Float(53))) AS DateTime) END) AS thaDate
, (CASE
WHEN DATEPART(hh, [timestamp]) > 6 AND DATEPART(hh, [timestamp]) < 15 THEN 1
WHEN DATEPART(hh, [timestamp]) > 14 AND DATEPART(hh, [timestamp]) < 23 THEN 2
WHEN CAST(DATEPART(hh, [timestamp]) AS INT) > 23 OR CAST(DATEPART(hh, [timestamp]) AS INT) < 7 THEN 3 END) AS thaShift
, DATEPART(hh, [timestamp]) AS thaOutPut
FROM DOWNTIMELOG
WHERE ([timestamp] >= CONVERT(DATETIME, '2005-12-10 00:00:00', 102))-PatP|||Thanks Pat,
That returns what I need. Now how/can I take this and using temp table join it to the ENTERED_TIME ( as in previous posts) table and provide the net between the two? If so can you give me an example of how to go about this?|||I figured it out. I managed by taking Pat's help and creating a view then joining it to the table. Now sure if this is the best way, but it seems to work.

Tuesday, February 14, 2012

Date/Time Stamp

When a record is written to a table (via a asp form), I'd like the time
and date from the server to automatically populate a column in that
table. From what I can tell, timestamp isn't working. I rather not
have the time come from the client.

Thanks for the help.Add a column with a default of CURRENT_TIMESTAMP. This is nothing to do
with TIMESTAMP, which is the SQL Server keyword for a row-versioning
column, not for date and time.

ALTER TABLE your_table ADD date_created DATETIME NOT NULL
CONSTRAINT df_your_table_date_created DEFAULT CURRENT_TIMESTAMP

--
David Portas
SQL Server MVP
--|||alternatively, you can also use as

ALTER TABLE your_table ADD date_created DATETIME NOT NULL
CONSTRAINT df_your_table_date_created DEFAULT getdate()

best Regards,
Chandra
http://groups.msn.com/SQLResource/
http://chanduas.blogspot.com/
------------

*** Sent via Developersdex http://www.developersdex.com ***