slow codes

1. Senior Member
Join Date
Dec 1969
Posts
276

## slow codes

Can some one plz tell me a better way to write this code?<BR>IF IsNull(TOID) AND IsNull(TKAID) THEN<BR> sql = " SELECT * from Prosjekt where PFylke = &#039;"&PFylke&"&#039; and PFylke = &#039;"& TFylkenr &"&#039;"<BR>Else<BR> sql = " SELECT * from Prosjekt where PKAID = &#039;"& TKAID &"&#039; and POID = &#039;"& TOID &"&#039; and PFylke = &#039;"& PFylke &"&#039; and Pfylke = &#039;"& TFylkenr &"&#039;"<BR>End IF<BR><BR>I don&#039;t even know If it&#039;s pssible to have two Pfylke = in one recordset?<BR><BR>

2. Senior Member
Join Date
Dec 1969
Posts
5,104

## How can it equal 2 things at the same time?

Try this:<BR><BR>sql = " SELECT * from Prosjekt where (PFylke = &#039;"&PFylke&"&#039; or PFylke = &#039;"& TFylkenr &"&#039;) "<BR><BR>IF Not IsNull(TOID) Then<BR> sql = sql & " and POID = &#039;" & TOID & "&#039; "<BR>End If<BR><BR>If Not IsNull(TKAID) THEN<BR> sql = sql & " and PKAID = &#039;"& TKAID &"&#039; "<BR>End If<BR><BR>-Doug

3. Senior Member
Join Date
Dec 1969
Posts
7,686

## RE: slow codes

I really wouldn&#039;t know what to recommend. Seems pretty OK to me.<BR>You could have as much Pfylkes in your WHERE statement as you want (whatever they may be).<BR><BR>You could use the IN function:<BR>WHERE Pfylke IN (&#039;a&#039;,&#039;b&#039;,&#039;c&#039;) etc. etc. Just a comma separated list with the values.

4. Senior Member
Join Date
Dec 1969
Posts
7,686

## better than my answer <eop>

.

5. Senior Member
Join Date
Dec 1969
Posts
276

## RE: slow codes

Thx alot, I&#039;m quite new at this so I need advices. But here comes my huge problem.<BR>See code below:<BR><BR><BR>PFylke=request.querystring("PFyl ke")<BR>StartTime = Timer <BR>tilgangsql = " select * from Tilganglinje where TLTID=&#039;"&TID&"&#039;"<BR>Set oRS=Application("oConn").Execute( tilgangsql )<BR>Do While NOT oRS.EOF <BR><BR>TKAID = oRS("TKAID")<BR>IF IsNull(TKAID) THEN<BR>TKAID = TKAID<BR>else<BR>TKAID = CInt(TKAID)<BR>End If<BR>TOID = oRS("TOID")<BR>IF IsNull(TOID) THEN<BR>TOID = TOID<BR>Else<BR>TOID = CInt(TOID)<BR>End If<BR>TFylkenr = oRS("TFylkenr")<BR>IF IsNull(TOID) AND IsNull(TKAID) THEN<BR> sql = " SELECT * from Prosjekt where PFylke = &#039;"&PFylke&"&#039; and PFylke = &#039;"& TFylkenr &"&#039;"<BR>Else<BR> sql = " SELECT * from Prosjekt where PKAID = &#039;"& TKAID &"&#039; and POID = &#039;"& TOID &"&#039; and PFylke = &#039;"& PFylke &"&#039; and Pfylke = &#039;"& TFylkenr &"&#039;"<BR>End IF<BR>set oRS2 = Application("oConn").Execute( sql )<BR>Do While NOT oRS2.EOF<BR><BR>This code is the best I could write, but I&#039;m afraid this is to much for iis, I&#039;ve looked at examples, but didn&#039;t find anyone fitting my problem. Could one of you plz give me an example of a better code?

6. Senior Member
Join Date
Dec 1969
Posts
5,104

.

7. Senior Member
Join Date
Dec 1969
Posts
5,104

## Did you *not* read my post?

I basically explained it all to you.<BR><BR>What are you having problems with?<BR><BR>What is the connection object doing in the Application variable? Read Craig&#039;s pethate post below about that. I think it&#039;s titled something like "NO NO NO NO NO".<BR><BR>-Doug

8. Senior Member
Join Date
Dec 1969
Posts
276

## RE: Did you *not* read my post?

I&#039;ve read that, but haven&#039;t had the chanse to change and didn&#039;t quite get it, There for I need more help. I&#039;ve tried to find a better way for weeks, but since I&#039;m not that into ASP yet I&#039;m having a little problems figuring out how, and where to put the elements of recordsets

9. Senior Member
Join Date
Dec 1969
Posts
5,104

Build the SQL my way.<BR><BR>Then, tell me what the problem is.<BR><BR>-Doug

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•