Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find Highest Number Without Building an Index

Status
Not open for further replies.

stanlyn

Programmer
Sep 3, 2003
945
US
Hi,

I need to find a way to get the row containing highest sessionid number WITHOUT building an index like I'm doing here. It takes too long to run and I'm trying to improve performance. Thanks! Here is the code...

Code:
Select 'rv_Session'
Index On SessionID Tag iSession
Set Order To iSession Desc
Go Top
Locate For Upper(Alltrim(rv_Session.SystemId)) == Upper(Alltrim(gcSystemId))

If Found('rv_Session')
    gnSessionId = rv_Session.SessionID + 1
Else
    gnSessionId = 1
Endif
 
Stanlyn said:
What is the difference with your use of ?m.lcSystemId and my use which is '<<lcSystemId>>' ?

Is one better than the other?

Looks like nobody answered this question. Yes, one is better. The ? notation protects you from SQL injection. That is, it keeps a hacker from getting access to your database:


And here's the funny version of this:
Tamar
 
Okay, coming back to this. I see I had a wrong understanding about the meaning of scope in SQL Server.

The same scope means the same function, procedure or the adhoc 'batch' of commands TABLEUPDATE creates. So even two successive SQLExecs are two separate scopes. Even when you uncheck Automatic Transactions in the view designer.

I showed you how you can circumvent this by defining a view the way it will either give you the one record of interest or none in your other thread. I'd go that route.

Chriss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top