OK, this is ASP/T-SQL, so it may be unfamiliar to some...
What I want is really easy... I'm just not too bright I guess, and my guru of choice is in a meeting for the day... so...
The code:
<code>
' Begin Query Logic
If trim(Request.QueryString("SearchFor") & " ") <> "" and trim(Request.QueryString("SearchFor") & " ") <> "Enter Keywords Here" Then
Session("SearchFor") = trim(Request.QueryString("SearchFor") & " ")
Else
Session("SearchFor") = ""
End If
If trim(Request.QueryString("OfType") & " ") <> "" Then
Session("OfType") = trim(Request.QueryString("OfType") & " ")
Else
Session("FAK") = ""
End If
intTerm = 0
Select Case trim(Request.QueryString("OfType") & " ")
Case "Origin"
intTerm = 1
Case "Destination"
intTerm = 2
Case "Commodity"
intTerm = 3
Case "Volume"
intTerm = 4
End Select
If trim(Request.QueryString("Direction") & " ") <> "" and trim(Request.QueryString("Direction") & " ") <> "All" Then
Session("Direction") = trim(Request.QueryString("Direction") & " ")
Else
Session("Direction") = ""
End If
If trim(Request.QueryString("FAK") & " ") <> "" Then
Session("FAK") = trim(Request.QueryString("FAK") & " ")
Else
Session("FAK") = ""
End If
If trim(Request.QueryString("Sort") & " ") <> "" Then
Session("Sort") = trim(Request.QueryString("Sort") & " ")
Else
Session("Sort") = "Desc"
End If
If trim(Request.QueryString("OrderBy") & " ") <> "" Then
Session("OrderBy") = trim(Request.QueryString("OrderBy") & " ")
Else
Session("OrderBy") = "ContractNum"
End If
Dim sqlText
Dim rsServiceContracts
sqlText = "Select Distinct ct.RecordStatus"
sqlText = sqlText & ", ct.TableId"
sqlText = sqlText & ", ct.ContractNum"
sqlText = sqlText & ", ct.CurrentAmendmentNum"
sqlText = sqlText & ", ct.Description"
sqlText = sqlText & ", ct.DateEffective"
sqlText = sqlText & ", ct.DateExpiration"
sqlText = sqlText & ", ct.DateFiling"
sqlText = sqlText & ", ct.FMCFilingNum"
If Session("Direction") <> "" Then sqlText = sqlText & ", SubTermNum AS SubTerm1"
sqlText = sqlText & " from Contract ct"
If (Session("OfType") = "Shipper" or Session("OfType") = "All") and trim(Session("SearchFor") & " ") <> "" Then
sqlText = sqlText & " left join Shipper sh on ct.ShipperTableID = sh.TableID"
End If
If ((intTerm <> 0 or Session("OfType") = "All") and trim(Session("SearchFor") & " ") <> "" ) or _
Session("Direction") <> "" Then
sqlText = sqlText & " left join ContractLines cl on ct.TableId = cl.ContractTableId"
End If
sqlText = sqlText & " where ct.CarrierId = " & Session("CarrierId")
If (Session("OfType") = "Shipper" or Session("OfType") = "All") and trim(Session("SearchFor") & " ") <> "" Then
sqlText = sqlText & " and "
If Session("OfType") = "All" and trim(Session("SearchFor") & " ") <> "" Then sqlText = sqlText & "("
sqlText = sqlText & "sh.ShipperName like '%" & FmtOdbcStrOut(Session("SearchFor")) & "%'"
End If
If ((intTerm <> 0 or Session("OfType") = "All") and trim(Session("SearchFor") & " ") <> "") or Session("Direction") <> "" Then
If intTerm <> 0 and trim(Session("SearchFor") & " ") <> "" Then
sqlText = sqlText & " and (cl.TermNum = " & intTerm
sqlText = sqlText & " and cl.SubTermNum = 0)"
End If
If Session("Direction") <> "" Then
If intTerm <> 1 Then
sqlText = sqlText & " and (cl.TermNum = 1"
sqlText = sqlText & " and cl.SubTermNum = 0"
sqlText = sqlText & " and SubTerm1 = 1)"
Else
sqlText = sqlText & " and (cl.TermNum = 1"
sqlText = sqlText & " and SubTerm1 = 1)"
End If
End If
If Session("OfType") = "All" and trim(Session("SearchFor") & " ") <> "" Then
If intTerm <> 1 and Session("Direction") <> "" Then sqlText = sqlText & " and cl.TermNum = 1"
If intTerm <> 2 Then sqlText = sqlText & " and cl.TermNum = 2"
If intTerm <> 3 Then sqlText = sqlText & " and cl.TermNum = 3"
If intTerm <> 4 Then sqlText = sqlText & " and cl.TermNum = 4"
sqlText = sqlText & " or"
ElseIf Session("Direction") = "" and intTerm <> 0 Then
sqlText = sqlText & " and"
End If
If trim(Session("SearchFor") & " ") <> "" Then
sqlText = sqlText & " (cl.TermShortDescription like '%" & FmtOdbcStrOut(Session("SearchFor")) & "%'"
sqlText = sqlText & " or cl.TermDescription like '%" & FmtOdbcStrOut(Session("SearchFor")) & "%'"
sqlText = sqlText & " or cl.ScopeDescription like '%" & FmtOdbcStrOut(Session("SearchFor")) & "%')"
End If
If Session("Direction") <> "" Then
If Session("Direction") = "Eastbound" or Session("Direction") = "Combination" Then
sqlText = sqlText & " and cl.TermShortDescription like '%EASTBOUND%'"
End If
If Session("Direction") = "Westbound" or Session("Direction") = "Combination" Then
sqlText = sqlText & " and cl.TermShortDescription like '%WESTBOUND%'"
End If
End If
End If
If Session("OfType") = "All" and trim(Session("SearchFor") & " ") <> "" Then sqlText = sqlText & ")"
If Session("MM_UserAuthorization") < 3 or Session["MM_UserAuthorization") > 4 Then
sqlText = sqlText & " and ct.RecordStatus <> 'H'"
Else
sqlText = sqlText & " and ct.RecordStatus = 'C'"
End If
sqlText = sqlText & " Order by ct.RecordStatus desc"
sqlText = sqlText & ", ct." & Session("OrderBy") & " " & Session("Sort")
Response.Write(sqlText)
Set rsServiceContracts = Conn.Execute(sqlText)
If Session("MM_UserAuthorization") <> 4 Then
If Session("AccessDate") < Date and Session["MM_UserAuthorization") <> 4 Then
strShowHistory = "Y"
sqlText = "Select RecordStatus"
sqlText = sqlText & ", TableId"
sqlText = sqlText & ", ContractNum"
sqlText = sqlText & ", CurrentAmendmentNum"
sqlText = sqlText & ", Description"
sqlText = sqlText & ", DateEffective"
sqlText = sqlText & ", DateExpiration"
sqlText = sqlText & ", DateFiling"
sqlText = sqlText & ", FMCFilingNum"
sqlText = sqlText & " from Contract"
sqlText = sqlText & " where CarrierId = " & Session("CarrierId")
sqlText = sqlText & " and DateExpiration >= '" & Session("AccessDate") & "'"
sqlText = sqlText & " and RecordStatus = 'H'"
sqlText = sqlText & " Order By RecordStatus desc"
sqlText = sqlText & ", " & Session("OrderBy") & " " & Session("Sort")
Set rsSCHistory = Conn.Execute(sqlText)
End If
End If
</code>
Should be pretty self explanatory. Keep in mind, this is pre-cleanup, before I "Find&Replace" Sessions with strings pulled from an array (which will be split() from either a single Session or cookie... I haven't decided yet) and the like.
RecordStatus = Current, History, Pending, Future, etc...
Once the main logic is done, it'll be a simple cut&paste for History.
There's money in tweaks later, but this has to go into production today so getting it working is the first priority...
So... I've messed up somewhere on my AS statement looks like. Here's the painstakingly recreated SQL statement if Direction = Eastbound and everything else is defaults (All or Null).
<code>
Select Distinct ct.RecordStatus, ct.TableId, ct.ContractNum, ct.CurrentAmendmentNum, ct.Description, ct.DateEffective, ct.DateExpiration, ct.DateFiling, ct.FMCFilingNum from Contract ct left join ContractLines cl on ct.TableId = cl.ContractTableId where ct.CarrierId = 50 and (cl.TermNum = 1 and cl.SubTermNum = 0 and cl.SubTermNum = 1) and cl.TermShortDescription like '%EASTBOUND%' and ct.RecordStatus <> 'H' Order by ct.RecordStatus desc, ct.ContractNum Desc
</code>
Yes, I know it's the ugliest code you've ever seen... I promise to clean it up later when I can spend some time on the couch mulling over the best way to tie the search function together... then I'll have my reports template...
What I want is really easy... I'm just not too bright I guess, and my guru of choice is in a meeting for the day... so...
The code:
<code>
' Begin Query Logic
If trim(Request.QueryString("SearchFor") & " ") <> "" and trim(Request.QueryString("SearchFor") & " ") <> "Enter Keywords Here" Then
Session("SearchFor") = trim(Request.QueryString("SearchFor") & " ")
Else
Session("SearchFor") = ""
End If
If trim(Request.QueryString("OfType") & " ") <> "" Then
Session("OfType") = trim(Request.QueryString("OfType") & " ")
Else
Session("FAK") = ""
End If
intTerm = 0
Select Case trim(Request.QueryString("OfType") & " ")
Case "Origin"
intTerm = 1
Case "Destination"
intTerm = 2
Case "Commodity"
intTerm = 3
Case "Volume"
intTerm = 4
End Select
If trim(Request.QueryString("Direction") & " ") <> "" and trim(Request.QueryString("Direction") & " ") <> "All" Then
Session("Direction") = trim(Request.QueryString("Direction") & " ")
Else
Session("Direction") = ""
End If
If trim(Request.QueryString("FAK") & " ") <> "" Then
Session("FAK") = trim(Request.QueryString("FAK") & " ")
Else
Session("FAK") = ""
End If
If trim(Request.QueryString("Sort") & " ") <> "" Then
Session("Sort") = trim(Request.QueryString("Sort") & " ")
Else
Session("Sort") = "Desc"
End If
If trim(Request.QueryString("OrderBy") & " ") <> "" Then
Session("OrderBy") = trim(Request.QueryString("OrderBy") & " ")
Else
Session("OrderBy") = "ContractNum"
End If
Dim sqlText
Dim rsServiceContracts
sqlText = "Select Distinct ct.RecordStatus"
sqlText = sqlText & ", ct.TableId"
sqlText = sqlText & ", ct.ContractNum"
sqlText = sqlText & ", ct.CurrentAmendmentNum"
sqlText = sqlText & ", ct.Description"
sqlText = sqlText & ", ct.DateEffective"
sqlText = sqlText & ", ct.DateExpiration"
sqlText = sqlText & ", ct.DateFiling"
sqlText = sqlText & ", ct.FMCFilingNum"
If Session("Direction") <> "" Then sqlText = sqlText & ", SubTermNum AS SubTerm1"
sqlText = sqlText & " from Contract ct"
If (Session("OfType") = "Shipper" or Session("OfType") = "All") and trim(Session("SearchFor") & " ") <> "" Then
sqlText = sqlText & " left join Shipper sh on ct.ShipperTableID = sh.TableID"
End If
If ((intTerm <> 0 or Session("OfType") = "All") and trim(Session("SearchFor") & " ") <> "" ) or _
Session("Direction") <> "" Then
sqlText = sqlText & " left join ContractLines cl on ct.TableId = cl.ContractTableId"
End If
sqlText = sqlText & " where ct.CarrierId = " & Session("CarrierId")
If (Session("OfType") = "Shipper" or Session("OfType") = "All") and trim(Session("SearchFor") & " ") <> "" Then
sqlText = sqlText & " and "
If Session("OfType") = "All" and trim(Session("SearchFor") & " ") <> "" Then sqlText = sqlText & "("
sqlText = sqlText & "sh.ShipperName like '%" & FmtOdbcStrOut(Session("SearchFor")) & "%'"
End If
If ((intTerm <> 0 or Session("OfType") = "All") and trim(Session("SearchFor") & " ") <> "") or Session("Direction") <> "" Then
If intTerm <> 0 and trim(Session("SearchFor") & " ") <> "" Then
sqlText = sqlText & " and (cl.TermNum = " & intTerm
sqlText = sqlText & " and cl.SubTermNum = 0)"
End If
If Session("Direction") <> "" Then
If intTerm <> 1 Then
sqlText = sqlText & " and (cl.TermNum = 1"
sqlText = sqlText & " and cl.SubTermNum = 0"
sqlText = sqlText & " and SubTerm1 = 1)"
Else
sqlText = sqlText & " and (cl.TermNum = 1"
sqlText = sqlText & " and SubTerm1 = 1)"
End If
End If
If Session("OfType") = "All" and trim(Session("SearchFor") & " ") <> "" Then
If intTerm <> 1 and Session("Direction") <> "" Then sqlText = sqlText & " and cl.TermNum = 1"
If intTerm <> 2 Then sqlText = sqlText & " and cl.TermNum = 2"
If intTerm <> 3 Then sqlText = sqlText & " and cl.TermNum = 3"
If intTerm <> 4 Then sqlText = sqlText & " and cl.TermNum = 4"
sqlText = sqlText & " or"
ElseIf Session("Direction") = "" and intTerm <> 0 Then
sqlText = sqlText & " and"
End If
If trim(Session("SearchFor") & " ") <> "" Then
sqlText = sqlText & " (cl.TermShortDescription like '%" & FmtOdbcStrOut(Session("SearchFor")) & "%'"
sqlText = sqlText & " or cl.TermDescription like '%" & FmtOdbcStrOut(Session("SearchFor")) & "%'"
sqlText = sqlText & " or cl.ScopeDescription like '%" & FmtOdbcStrOut(Session("SearchFor")) & "%')"
End If
If Session("Direction") <> "" Then
If Session("Direction") = "Eastbound" or Session("Direction") = "Combination" Then
sqlText = sqlText & " and cl.TermShortDescription like '%EASTBOUND%'"
End If
If Session("Direction") = "Westbound" or Session("Direction") = "Combination" Then
sqlText = sqlText & " and cl.TermShortDescription like '%WESTBOUND%'"
End If
End If
End If
If Session("OfType") = "All" and trim(Session("SearchFor") & " ") <> "" Then sqlText = sqlText & ")"
If Session("MM_UserAuthorization") < 3 or Session["MM_UserAuthorization") > 4 Then
sqlText = sqlText & " and ct.RecordStatus <> 'H'"
Else
sqlText = sqlText & " and ct.RecordStatus = 'C'"
End If
sqlText = sqlText & " Order by ct.RecordStatus desc"
sqlText = sqlText & ", ct." & Session("OrderBy") & " " & Session("Sort")
Response.Write(sqlText)
Set rsServiceContracts = Conn.Execute(sqlText)
If Session("MM_UserAuthorization") <> 4 Then
If Session("AccessDate") < Date and Session["MM_UserAuthorization") <> 4 Then
strShowHistory = "Y"
sqlText = "Select RecordStatus"
sqlText = sqlText & ", TableId"
sqlText = sqlText & ", ContractNum"
sqlText = sqlText & ", CurrentAmendmentNum"
sqlText = sqlText & ", Description"
sqlText = sqlText & ", DateEffective"
sqlText = sqlText & ", DateExpiration"
sqlText = sqlText & ", DateFiling"
sqlText = sqlText & ", FMCFilingNum"
sqlText = sqlText & " from Contract"
sqlText = sqlText & " where CarrierId = " & Session("CarrierId")
sqlText = sqlText & " and DateExpiration >= '" & Session("AccessDate") & "'"
sqlText = sqlText & " and RecordStatus = 'H'"
sqlText = sqlText & " Order By RecordStatus desc"
sqlText = sqlText & ", " & Session("OrderBy") & " " & Session("Sort")
Set rsSCHistory = Conn.Execute(sqlText)
End If
End If
</code>
Should be pretty self explanatory. Keep in mind, this is pre-cleanup, before I "Find&Replace" Sessions with strings pulled from an array (which will be split() from either a single Session or cookie... I haven't decided yet) and the like.
RecordStatus = Current, History, Pending, Future, etc...
Once the main logic is done, it'll be a simple cut&paste for History.
There's money in tweaks later, but this has to go into production today so getting it working is the first priority...
So... I've messed up somewhere on my AS statement looks like. Here's the painstakingly recreated SQL statement if Direction = Eastbound and everything else is defaults (All or Null).
<code>
Select Distinct ct.RecordStatus, ct.TableId, ct.ContractNum, ct.CurrentAmendmentNum, ct.Description, ct.DateEffective, ct.DateExpiration, ct.DateFiling, ct.FMCFilingNum from Contract ct left join ContractLines cl on ct.TableId = cl.ContractTableId where ct.CarrierId = 50 and (cl.TermNum = 1 and cl.SubTermNum = 0 and cl.SubTermNum = 1) and cl.TermShortDescription like '%EASTBOUND%' and ct.RecordStatus <> 'H' Order by ct.RecordStatus desc, ct.ContractNum Desc
</code>
Yes, I know it's the ugliest code you've ever seen... I promise to clean it up later when I can spend some time on the couch mulling over the best way to tie the search function together... then I'll have my reports template...