Showing posts with label theother. Show all posts
Showing posts with label theother. Show all posts

Monday, March 12, 2012

Help with 2 datetime fields-1 stores date, the other time

Hi,
We have a lame app that uses 2 datetime(8) fields, 1 stores the date, the
other the time.
example query:

select aud_dt, aud_tm
from orders

results:
aud_dt aud_tm
2006-06-08 00:00:00.000 1900-01-01 12:32:26.287

I'm trying to create a query that give me records from the current date in
the past hour.
Here's a script that gives me todays date but I cannot figure out the time:

select aud_dt, aud_tm, datediff(d,aud_dt,getdate()), datediff(mi, aud_tm,
getdate())
from orders
where (datediff(d,aud_dt,getdate()) = 0)

results:
aud_dt aud_tm
datediff(0=today) timediff (since 1900-01-01)
2006-06-08 00:00:00.000 1900-01-01 12:32:26.287 0
55978689

I added this next part to the above query but it does not work since the
date/time is from 1900-01-01
and (datediff(mi, aud_tm, getdate()) <= 60)

Thanks for any help.rdraider wrote:
> Hi,
> We have a lame app that uses 2 datetime(8) fields, 1 stores the date, the
> other the time.
> example query:
> select aud_dt, aud_tm
> from orders
> results:
> aud_dt aud_tm
> 2006-06-08 00:00:00.000 1900-01-01 12:32:26.287
> I'm trying to create a query that give me records from the current date in
> the past hour.
> Here's a script that gives me todays date but I cannot figure out the time:
> select aud_dt, aud_tm, datediff(d,aud_dt,getdate()), datediff(mi, aud_tm,
> getdate())
> from orders
> where (datediff(d,aud_dt,getdate()) = 0)
> results:
> aud_dt aud_tm
> datediff(0=today) timediff (since 1900-01-01)
> 2006-06-08 00:00:00.000 1900-01-01 12:32:26.287 0
> 55978689
>
> I added this next part to the above query but it does not work since the
> date/time is from 1900-01-01
> and (datediff(mi, aud_tm, getdate()) <= 60)
>
> Thanks for any help.

The correct way would be to fix the database and use one datetime
column. I'll assume you already know this and that it isn't possible
for some reason.

So, if you want to combine those two into one datetime field (which you
could then use in a query however you like) you can use something like
this:

cast((cast(aud_dt as float) + cast(aud_tm as float)) as datetime)

although you might lose some precision in the miliseconds. If that's
unacceptable, you can instead do this:

convert(datetime, convert(varchar(10), aud_dt, 1) + ' ' +
convert(varchar(10), aud_tm, 14))|||These both work well. Miliseconds don't matter.

Thank you.

"ZeldorBlat" <zeldorblat@.gmail.com> wrote in message
news:1149832253.251499.139790@.h76g2000cwa.googlegr oups.com...
> rdraider wrote:
>> Hi,
>> We have a lame app that uses 2 datetime(8) fields, 1 stores the date, the
>> other the time.
>> example query:
>>
>> select aud_dt, aud_tm
>> from orders
>>
>> results:
>> aud_dt aud_tm
>> 2006-06-08 00:00:00.000 1900-01-01 12:32:26.287
>>
>> I'm trying to create a query that give me records from the current date
>> in
>> the past hour.
>> Here's a script that gives me todays date but I cannot figure out the
>> time:
>>
>> select aud_dt, aud_tm, datediff(d,aud_dt,getdate()), datediff(mi, aud_tm,
>> getdate())
>> from orders
>> where (datediff(d,aud_dt,getdate()) = 0)
>>
>> results:
>> aud_dt aud_tm
>> datediff(0=today) timediff (since 1900-01-01)
>> 2006-06-08 00:00:00.000 1900-01-01 12:32:26.287 0
>> 55978689
>>
>>
>> I added this next part to the above query but it does not work since the
>> date/time is from 1900-01-01
>> and (datediff(mi, aud_tm, getdate()) <= 60)
>>
>>
>> Thanks for any help.
> The correct way would be to fix the database and use one datetime
> column. I'll assume you already know this and that it isn't possible
> for some reason.
> So, if you want to combine those two into one datetime field (which you
> could then use in a query however you like) you can use something like
> this:
> cast((cast(aud_dt as float) + cast(aud_tm as float)) as datetime)
> although you might lose some precision in the miliseconds. If that's
> unacceptable, you can instead do this:
> convert(datetime, convert(varchar(10), aud_dt, 1) + ' ' +
> convert(varchar(10), aud_tm, 14))

Friday, February 24, 2012

Help selecting Veritas products

I have two Windows Server 2003 servers. One is a domain controller and the
other has SQL Server. The tape drive is in the domain controller. Am I OK
with Backup Exec 10d for Windows Servers and a remote agent for SQL Server
for Windows Server?
ThanksHi
You could back up your database to disc (a network resource) and then you
would not need the remote agent.
John
"r042wal" wrote:

> I have two Windows Server 2003 servers. One is a domain controller and th
e
> other has SQL Server. The tape drive is in the domain controller. Am I O
K
> with Backup Exec 10d for Windows Servers and a remote agent for SQL Server
> for Windows Server?
> Thanks
>
>|||r042wal wrote:
> I have two Windows Server 2003 servers. One is a domain controller and th
e
> other has SQL Server. The tape drive is in the domain controller. Am I O
K
> with Backup Exec 10d for Windows Servers and a remote agent for SQL Server
> for Windows Server?
> Thanks
>
Don't use a backup agent to do SQL backups, they tend to be problematic
at best, and take longer to backup than a "normal" SQL backup. Just use
the SQL command BACKUP to dump the database contents to a disk file,
then backup that disk file using your tape backup software.
Tracy McKibben
MCDBA
http://www.realsqlguy.com|||Tracy, can the backup command in SQL be automated? I want to do a scheduled
backup nightly.
Thanks
"Tracy McKibben" <tracy@.realsqlguy.com> wrote in message
news:uXSKJRmuGHA.3392@.TK2MSFTNGP04.phx.gbl...
> r042wal wrote:
> Don't use a backup agent to do SQL backups, they tend to be problematic at
> best, and take longer to backup than a "normal" SQL backup. Just use the
> SQL command BACKUP to dump the database contents to a disk file, then
> backup that disk file using your tape backup software.
>
> --
> Tracy McKibben
> MCDBA
> http://www.realsqlguy.com|||Hi
If you right click the database in the treeview of Enterprise Manager and
choose the backup option, then at the bottom of the general tab is an option
to schedule the backup. Alternatively you can look at using a maintenance
plan which will also allow you to schedule tasks for multiple databases and
allows you to do other things like index reorganization. To create a new
maintenance plan check out the Management branch, right click Database
Maintenance Plans and choose New Maintenance Plan.
John
"r042wal" wrote:

> Tracy, can the backup command in SQL be automated? I want to do a schedul
ed
> backup nightly.
> Thanks
> "Tracy McKibben" <tracy@.realsqlguy.com> wrote in message
> news:uXSKJRmuGHA.3392@.TK2MSFTNGP04.phx.gbl...
>
>|||r042wal wrote:
> Tracy, can the backup command in SQL be automated? I want to do a schedul
ed
> backup nightly.
>
Absolutely, just setup a job in SQL Agent that runs the necessary BACKUP
command(s). You might also have a look at a script I've written that I
use to do backups:
http://realsqlguy.com/twiki/bin/vie...realsqlguy.com