Showing posts with label via. Show all posts
Showing posts with label via. Show all posts

Wednesday, March 21, 2012

Row Not Inserting At Bottom

Greetings, SQLanoids,

When I insert a row of data into a table via a stored procedure, the row SOMETIMES gets inserted at the bottom, and sometimes gets inserted at another random location (top, midding, etc). I am using Microsoft SQL Server.

Dea anybody know the cause of this? Or how to ensure that the row gets inserted at the bottom?

I am a novice SQL Server user, but this seems like a simple problem that the more advanced users solved long ago. Thanks in advance!This behavior you are seeing is by design. SQL Server decides where to put the data and we have no control over that. Nor, really, is it important.

If you need the data to come out of the database in a particular order, you need to use an ORDER BY statement. If it is important for you to know the order in which records were inserted into the database, I suggest using a DateAdded column with a Default Value of GETDATE() so that SQL Server will automatically populate this for you. You might also consider using a column flagged as an IDENTITY for this purpose.

Terri|||Thank you for the response. I tried your advice and it worked well. However, I noticed only one problem.

When it inserts the date, using a Default Value of GETDATE(), and using data type smalldatetime, the field gets inserted as "1/17/2005 2:23:00 AM".

However, when I set the data type to vnarchar, the field gets inserted as "Jan 17 2005 2:23AM"

I prefer the second method, as it spells out the first 3 letters of the month. The problem, however, is that the ORDER BY statement does not accurately pull the records when stored as nvarchar. It is unable to distinguish between AM and PM and pulls the records in order of numeric chronology only.

Do you know how I can fix this, and still store the items as "Jan..."?

Thanks|||Use a datetime data type to store datetime data. Use output formatting to display the data in the desired format (either by using CAST or CONVERT, or in the ASP.NET front end).

Terri

Row Locking in SQL via ADO (VB 6)

Hi,

I'm trying to use the pessimistic row locking of SQL to get following result.

When a customer form is openend, the row should be locked for writing.
This lock should be left open until the user closes the customer form.

I cannot use transactions because there can be more then 1 customer form open in the same app. In ADO a connection is IN transaction or is NOT, nested transactions are not supported.

How can I keep this row locked on SQL and this until I unlock it or the connection is broken ( in case of problems on client machine )?
And how can I see on another machine of this row ( customer ) is already locked so I can open him in read-only?

For the moment I'm using extra fields that hold the info wether the customer is locked en by whom. But that's on application level, not on DB-level.

I hope this is clear enough.I've often wondered if there is any reason that justifies pessimistic locking. So far I haven't found one. I recommend shutting down the SQL Server to get pessimistic locking... If the box is off, no other user can modify your data, and it makes the scaling problems caused by pessimistic locking less of a problem.

To answer your question more directly, yes pessimistic locking can be done using ADO. It has been a long time since I've had any reason to try to hurt myself that badly after I established that it was possible, so I'm fuzzy on the details.

-PatP|||This may be what you're looking for:

http://www34.brinkster.com/a213855/|||Pat,

I'm convinced that pessimistic locking is not the ideal solution.
How should i take care of the record-locking then?

Regards,

Sven Peeters|||Ummmm, optimistic locking (http://search.microsoft.com/search/results.aspx?qu=%22optimistic+locking%22&View=msdn&st=b&c=0&s=1&swc=0)? I especially reccomend An update on UPDATing (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvbdev00/html/vb00e1.asp), but there are lots of good articles to read!

-PatP

Monday, March 12, 2012

Row Count SSIS

I need help implementing row count on a SSIS Package
*** Sent via Developersdex http://www.codecomments.com ***
That's a pretty skimpy requirement for us to help you on Michael! :-) Can
you please elaborate?
TheSQLGuru
President
Indicium Resources, Inc.
"Michael Watford" <mwatford@.edgecorp.us> wrote in message
news:%23nljMuIyHHA.1168@.TK2MSFTNGP02.phx.gbl...
>I need help implementing row count on a SSIS Package
>
> *** Sent via Developersdex http://www.codecomments.com ***

Row Count SSIS

I need help implementing row count on a SSIS Package
*** Sent via Developersdex http://www.developersdex.com ***That's a pretty skimpy requirement for us to help you on Michael! :-) Can
you please elaborate?
--
TheSQLGuru
President
Indicium Resources, Inc.
"Michael Watford" <mwatford@.edgecorp.us> wrote in message
news:%23nljMuIyHHA.1168@.TK2MSFTNGP02.phx.gbl...
>I need help implementing row count on a SSIS Package
>
> *** Sent via Developersdex http://www.developersdex.com ***

Row Count SSIS

I need help implementing row count on a SSIS Package
*** Sent via Developersdex http://www.codecomments.com ***That's a pretty skimpy requirement for us to help you on Michael! :-) Can
you please elaborate?
TheSQLGuru
President
Indicium Resources, Inc.
"Michael Watford" <mwatford@.edgecorp.us> wrote in message
news:%23nljMuIyHHA.1168@.TK2MSFTNGP02.phx.gbl...
>I need help implementing row count on a SSIS Package
>
> *** Sent via Developersdex http://www.codecomments.com ***