Showing posts with label adds. Show all posts
Showing posts with label adds. Show all posts

Sunday, March 11, 2012

DateTime error in stored procedure

Hi;

I have a stored procedure simply adds userid,logintime and status to db but I have an error when running procedure can you help me please??

Create Procedure AddLog
(
@.User char(10),
@.DLogon DateTime(8),
@.Status bit
)
As
Insert Into Log(UserID,LogInTime,Online)
Values(@.User,DLogon,Status)

ERROR:

Server: Msg 128, Level 15, State 1, Procedure AddLog, Line 9
The name 'DLogon' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted.You are missing a couple of @. signs. Should be:


Create Procedure AddLog
(
@.User char(10),
@.DLogon DateTime(8),
@.Status bit
)
As
Insert Into Log(UserID,LogInTime,Online)
Values(@.User,@.DLogon,@.Status)

Sunday, February 19, 2012

DATEDIFF Weirdness!

Does not compute!!
Can someone explain why DATEDIFF function adds 3 hours to the result?!
I constantly had false results and I then noticed that the time values
are incorrect. Then I made this query to check it:
select DATEDIFF(second, 'jan 1 1970', '2003-08-14')
It returns: 1060819200
Then I made a nice perl script to prove my point:
#!c:\perl\bin\perl.exe -w
print "TIME IS: " . localtime(1060819200);
Result is: Thu Aug 14 03:00:00 2003 (!?)
My Server and Client-machines are both set to same time zone, same date,
same time... So where does this extra 3 hours come from? Does it have
sth to do with UTC-time as GETUTCDATE() returns a time that is 3 hours
behind the time of my machines (Finnish time...).
But anyway, how can I get the DATEDIFF-function to work properly. I
really don't need the extra 3 hours... ;)
Oh, BTW... it's SQL Server 2000 I'm talking about and Windows 2000
Server (SQL Server) & Professional (SQL Server client).
-N-The problem is not with SQL Server it is with the way you are calling
localtime.
This function converts the value returned by time to a nine-element list
with the time corrected for the local time zone.
http://www.ib-perl.org/class/localtime.html
"Niko" <niko.ratto@.noSPAMkia.fi> wrote in message
news:TcN_a.9951$g4.193781@.news1.nokia.com...
> Does not compute!!
> Can someone explain why DATEDIFF function adds 3 hours to the result?!
> I constantly had false results and I then noticed that the time values
> are incorrect. Then I made this query to check it:
> select DATEDIFF(second, 'jan 1 1970', '2003-08-14')
> It returns: 1060819200
> Then I made a nice perl script to prove my point:
> #!c:\perl\bin\perl.exe -w
> print "TIME IS: " . localtime(1060819200);
> Result is: Thu Aug 14 03:00:00 2003 (!?)
>
> My Server and Client-machines are both set to same time zone, same date,
> same time... So where does this extra 3 hours come from? Does it have
> sth to do with UTC-time as GETUTCDATE() returns a time that is 3 hours
> behind the time of my machines (Finnish time...).
> But anyway, how can I get the DATEDIFF-function to work properly. I
> really don't need the extra 3 hours... ;)
> Oh, BTW... it's SQL Server 2000 I'm talking about and Windows 2000
> Server (SQL Server) & Professional (SQL Server client).
> -N-
>

Tuesday, February 14, 2012

dateadd update works but adds 2 or 3 yrs-not 1

I have a page that is supposed to add a year to a record when it loads. The problem is that it adds 2 or three years instead.
Here is the page_load event:
Sub page_load(sender as object, e as eventargs)
Try
Dim connection As SqlConnection = new SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim command As SqlCommand = new SqlCommand("Updateexpiredate", connection)
command.CommandType = CommandType.StoredProcedure

Dim param0 As SqlParameter = new SqlParameter("@.memberid",SqlDbType.Int)
param0.Direction = ParameterDirection.Input
param0.Value = memberid
command.Parameters.Add(param0)

connection.Open()
command.ExecuteNonQuery()
connection.Close()
myerror.Text = "Thank You! Your account was updated"
Catch ex As Exception
myerror.Text = ex.Message
End Try
End Sub

And here is the SPROC:
CREATE PROCEDURE Updateexpiredate
(
@.memberid int
)
AS
UPDATE
members
SET
expiredate=(dateadd(year,1,expiredate))<--I also tried expiredate=(dateadd(month,12,expiredate)) with the same results
WHERE
memberID = @.memberID
GO
... I'm assuming you're calling that method or procedure 2 or three time. :)

edited: Step through your app. It could be that it's called multiple times.|||How do I do that?
I don't even know where to begin with that.
Thanks|||The first thing I would do is turn tracing on for the page, and do a trace.write as the command right before the ExecuteNonQuery. This should give you more information on how many times that part of your code is being executed.

If you are not familiar with trace.write, look here:Trace Logging to Page Output. That is a good debugging tool to have in your pocket.

Terri|||What do you use to develop in? Is it Visual Studio, DreamWeaver, WebMatrix, notepad?

Date/Time stamp

Hi All,

I have a script that adds the date/time stamp to a file in the following format:

200701120149PM.

here is the script:

set dttm=%~t1
for /F "tokens=1-6 delims=/: " %%i in ("%dttm%") do (

set date=%%k%%i%%j%%l%%m
)

I need to display the time as military. How can I do that?

Thanks.What is that?

Can't you use T-SQL?

What's the table definition (DDL) look like?|||This is a DOS command that displays the system date/time.
What table are you refering to?|||Well, since this is a MS SQL Server forum, you might want to ask a question about that, othwerwise, there might be another board that can help you out with DOS|||Definitely the wrong forum for this question. Nevertheless, I think the answer may depend on your regional settings; when I run it, the output is fine (ie, no AM/PM, just a military hour).

This site (http://www.robvanderwoude.com/index.html)has some good stuff on DOS scripts...

Regards,

hmscott