Click to See Complete Forum and Search --> : SQL and Date


Caesar
09-29-2000, 10:20 AM
Hi!

Can someone help me here:

I am trying to insert a date field into a table (SQL Server)
For example my table consists of 2 fields. I am using .inc file in which
i pass some values to a procedure in that file (.inc)
TableName: Users
Fields: UserID (prim), username (nvarchar), lastsession (datetime)

Now I have a statement that looks like this
Insert Into Users (Username, Lastsession) Values('" & name & "', " & now()
& ")"

However when this statement gets executed I get some error. I have also tried
formatDateTime( now(), vbshortDDate)

Any solution to this!!???

Thanks much

Caesar Mensah
09-29-2000, 10:42 AM
I have attempted your solution however this is what I get

Error Type:
Microsoft VBScript compilation (0x800A0401)
Expected end of statement
/granta/administration/granta.inc, line 222, column 41
InsertAuthor = InsertAuthor & "VALUES('" GrantARS("Ref") & "', '" & FacName
& "', " & GETDATE() & ", '" & GrantARS("Phone") & "', " & GETDATE() & ",
1)"
----------------------------------------^



"Colin McGuigan" <colin@chicor.com> wrote:
>Caesar <c_mensah@hotmail.com> wrote in message
>news:39d4a512$1@news.devx.com...
>> Now I have a statement that looks like this
>> Insert Into Users (Username, Lastsession) Values('" & name & "', " & now()
>> & ")"
>>
>> However when this statement gets executed I get some error. I have also
>tried
>> formatDateTime( now(), vbshortDDate)
>>
>> Any solution to this!!???
>>
>> Thanks much
>
>Either put ''s around the date:
>
>Insert Into Users (Username, Lastsession) Values('" & name & "', '" & now()&
>"')"
>
>Or use SQL Server's GETDATE() function instead:
>
>Insert Into Users (Username, Lastsession) Values('" & name & "', GETDATE())"
>
>--
>Colin McGuigan
>
>
>

Colin McGuigan
09-29-2000, 10:50 AM
Caesar <c_mensah@hotmail.com> wrote in message
news:39d4a512$1@news.devx.com...
> Now I have a statement that looks like this
> Insert Into Users (Username, Lastsession) Values('" & name & "', " & now()
> & ")"
>
> However when this statement gets executed I get some error. I have also
tried
> formatDateTime( now(), vbshortDDate)
>
> Any solution to this!!???
>
> Thanks much

Either put ''s around the date:

Insert Into Users (Username, Lastsession) Values('" & name & "', '" & now()&
"')"

Or use SQL Server's GETDATE() function instead:

Insert Into Users (Username, Lastsession) Values('" & name & "', GETDATE())"

--
Colin McGuigan

Colin McGuigan
09-29-2000, 11:28 AM
Caesar Mensah <c_mensah@hotmail.com> wrote in message
news:39d4aa5d$1@news.devx.com...
>
> I have attempted your solution however this is what I get
>
> Error Type:
> Microsoft VBScript compilation (0x800A0401)
> Expected end of statement
> /granta/administration/granta.inc, line 222, column 41
> InsertAuthor = InsertAuthor & "VALUES('" GrantARS("Ref") & "', '" &
FacName
> & "', " & GETDATE() & ", '" & GrantARS("Phone") & "', " & GETDATE() & ",
> 1)"

That's wonderful. Not to be rude, or anything, but the problem is with your
VBScript statement, not the SQL that I gave.

Specifically, you're missing the ampersand (&) right before GrantARS("Ref"):

VALUES('" GrantARS("Ref")

should be

VALUES('" & GrantARS("Ref")

Secondly, GETDATE() is a SQL function, not a VBScript one. It should be
part of the literal string (like INSERT, VALUES, etc), so that:

, " & GETDATE() & ",

should be

, GETDATE(),

Note that you use GETDATE() twice, so you need to make sure it's fixed in
both places.

--
Colin McGuigan