 |
| SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

May 12th, 2004, 01:35 AM
|
|
Authorized User
|
|
Join Date: Dec 2003
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
column
I have 1 column must contain value of current time-(datatype datetime),
can I set the column automatically so the data is always update?,
( I have no idea, instead insert current time into database..everytime I want to use this database)..thank you.
__________________
 Suzila
|
|

May 12th, 2004, 04:59 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
|
|
dear friend:
ur Question was not clear, but what u need is
if u describe much clear, I'll try to be much helpfull.
Always:),
Hovik Melkomian.
|
|

May 12th, 2004, 05:23 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
|
|
You can set that GETDATE() as the COLUMN's default value, so that everytime you insert a row, you can leave out this date column, and insert values for other columns, and this would contain the current date/time stamp when the records was inserted.
But while updating the records, it doesnt get updated, unless you explicitly give value for this date_COLUMN.
Hope that helps
Cheers!
-Vijay G
|
|

May 12th, 2004, 08:13 PM
|
|
Authorized User
|
|
Join Date: Dec 2003
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
thank you, happygv and melvik
sorry, i'm sure you are not very clear..so i'll tell you what i want to do..but i'm not sure wether it's possible or not.
I have 1 table with 3 column
column 1 : session (eg: 1),
column 2 :start (eg: 8:00:00 AM),
column 3: end (eg:10:00:00 AM)
I want to determine which session I'm in now by using sql statement, like this one
SELECT session, CONVERT(datetime, start, 9) AS start, CONVERT(datetime, end, 9) AS end, CONVERT(datetime, t, 9) AS t
FROM dbo.sessi
WHERE (end > t) AND (start < =t)
t = should be current time, but I can't read the variables directly from my form., unless I take it from database.
So I add another column named t, so I can store the current time.
what I want to ask : can I set the t column to be auto update for current time value. And may I know - formula is what for?
thank you
|
|

May 13th, 2004, 04:01 AM
|
|
Authorized User
|
|
Join Date: Dec 2003
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Another question:
Howcan I set start column (datatype datetime) to be 24hours format?
because its automatically give AM/PM...
|
|

May 13th, 2004, 05:47 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Regarding you previous post, as your question wasn't clear it went wrong somehow.
You can do that as said in Melvik's post, and you dont have to use another column "t" as you did.
What is the datatype of Start and End Columns? If they are DateTime types, then there are some flaws that I would like to point in your query.
Doing a CONVERT(datetime, start, 9), doesn't make any big difference, since Start is itself a datetime and converting it to datetime again doesn't make sense.
If it wasn't DATATIME Type in the table, then you are making a mistake of converting it in to datetime with a format that puts AM/PM in it. Format CODE 9 - converts it into - "May 13 2004 10:29:18:223AM"
So you got to choose the right format. I would prefer FORMAT CODE 121 in your case if "START" is a DATETIME type, something like this should do.
You can substitute "t" with getdate() function.
But the biggest doubt in my mind is, what is that you are trying to do in your WHERE clause? Can you explain a bit on that?
Regarding your last POST,
If you are looking at your records in Enterprise Manager, then it would show you as AM/PM. That is how it is.
First do a
Select Getdate()
Go
in your query analyser and see what the output is. If that is in the format of "yyyy-mm-dd hh:mm:ss:mss" then you should find no problem with its manipulation. This is the default format of datetime datatypes. Else you will have to change the date format of you SQL Server.
select TOP 1 start from dbo.session --not sure about your table name
Go
Please cross check, this should also be in same format.
Hope that Helps.
Cheers!
-Vijay G
|
|

May 14th, 2004, 12:04 AM
|
|
Authorized User
|
|
Join Date: Dec 2003
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
happygv,:)thank you..your explanation help me to find the solution..
my solution, like this:
SELECT session
FROM dbo.sessi
WHERE
(start < CONVERT(varchar(30), GETDATE(), 114)) AND (end > CONVERT(varchar(30), GETDATE(), 114))
|
|
 |