Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Wishlist

Author  Topic 

DanielAc
Starting Member

5 Posts

Posted - 2003-09-19 : 08:22:38
I am developing a Wishlist web app. I have 2 tables, 1 table to hold the GUID and LastAccessedDate and another table to hold the wishlist items and the GUID. I am using the following code, but I cannot get a record into the SQL database, nor am I getting an error! What gives? The uniqueidentifier data type is already set to add the GUID field automatically with a default value of (newid()) and is RowGuid toggled to Yes.

Dim strUNID
strUNID = Request.Cookies("CookieDough")("UNID")

If "" & strUNID = "" Then
' it's not null, but it is an empty string, so treat it as null
sSql = "UPDATE tblWishID SET fldLastDate = GetDate()"
conn.Execute(sSql)
End If

dsdeming

479 Posts

Posted - 2003-09-19 : 08:30:08
This is an update, not an insert, so it can't really have anything to do with your not being able to get a record into the database. In addition, your update statement has no where clause, so you're updating fldLastDate in all rows with the same value.

Dennis
Go to Top of Page

DanielAc
Starting Member

5 Posts

Posted - 2003-09-19 : 08:37:40
Oh my Goodness!! I did not see that! I might have never seen it, I get to thinking ahead in the design! :)

Is this syntax correct if I want to INSERT a *NEW* record?

sSql = "INSERT INTO tblWishID (fldLastDate) VALUES (GetDate())"
conn.Execute(sSql)

Go to Top of Page

DanielAc
Starting Member

5 Posts

Posted - 2003-09-19 : 11:20:37
Can I get some idea of how to make this work based on the comments I have added to the code below. Thank you. This is a Wish List app using a random value placed into a client cookie and 2 back-end sql database tables.


Dim strUNID
strUNID = Request.Cookies("CookieDough")("UNID")

If "" & strUNID = "" Then
' it's not null, but it is an empty string, so treat it as null * OPEN DATABASE tblWishID assign GUID from the database and INSERT date
sSql = "INSERT INTO tblWishID (fldLastDate) VALUES (GetDate())"
conn.Execute(sSql) ' <---------------- is there a way to lock this until we get the value of the GUID field it is going to create?

' AND set the cookie based on the value of fldWishID we just put into the database!!
' Since we do not know the value of fldWishID because it is a random GUID we have to query the database, but how?
' We have no way to determine which record was just added...
' Is there a way to find out what the value of fldWishID was when we did the INSERT of the Date?


Response.Cookies("CookieDough")("UNID") = rs("fldWishID")

End If
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-09-19 : 12:23:18
Why aren't you putting your T-SQL code in stored procedures? You'll get better performance, easier to manage T-SQL code, and better security.

Tara
Go to Top of Page

DanielAc
Starting Member

5 Posts

Posted - 2003-09-19 : 12:41:35
Well the main reason is because I do not really know how.

The second reason is that I have to build it like this first, and then later if it is really important I can try to make it into a SP.

But back to my original question also, I was thinking if I create a 3rd column in this table so it would GUID, Date, and Autonumber then I could accomplish my goals.

What do you think?
Go to Top of Page

DanielAc
Starting Member

5 Posts

Posted - 2003-09-19 : 14:31:56
Does anyone know how I can do this using @@Identity?
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2003-09-19 : 14:42:16
Well...if you already created a table

CREATE TABLE myTable99(col1 int, col2 int)
GO

You can add an identity column (Access autonumber, sort of) with:

ALTER TABLE myTable99 ADD col3 int IDENTITY(1,1)
GO




Brett

8-)

SELECT @@POST=NewId()

That's correct! It's an AlphaNumeric!
Go to Top of Page
   

- Advertisement -