I'm facing issues while writing the below code in SQL developer:
'If Trim$(psFromDate) <> "" and NOT ISNULL(psFromDate) AND Trim$(psToDate) <> "" and NOT ISNULL(psToDate) Then
select case ps_datetype
CASE "CTA"
wc = wc & " AND (trunc(sf_get_local (p_con.created_date,p_con.cdate_tz_code)) Between "
wc = wc & " TO_DATE (" & "'" & sFromDate & "'" & ", 'DD/MM/YYYY') "
wc = wc & " AND TO_DATE (" & "'" & sToDate & "'" & ", 'DD/MM/YYYY'))"
'CASE "ATA"
CASE "VAD"
wc = wc & " AND trunc(sf_get_local(route_s.orgn_vsl_arvl_date,route_s.orgn_vsl_arvl_date_tz_code)) Between "
wc = wc & " TO_DATE (" & "'" & sFromDate & "'" & ", 'DD/MM/YYYY') "
wc = wc & " AND TO_DATE (" & "'" & sToDate & "'" & ", 'DD/MM/YYYY')"
CASE "ETA"
wc = wc & " AND TRUNC(sf_get_local(route_s.arrival_date,route_s.arrival_date_tz_code)) Between "
wc = wc & " TO_DATE (" & "'" & sFromDate & "'" & ", 'DD/MM/YYYY') "
wc = wc & " AND TO_DATE (" & "'" & sToDate & "'" & ", 'DD/MM/YYYY')"
END SELECT
'End If
I tried the below code but no luck:
Where (case when pstatustype='CTA' then (p_con.created_date Between to_date('&1','DD-MON-YYYY:HH24:MI:SS')
AND to_date('&2','DD-MON-YYYY:HH24:MI:SS'))
when pstatustype='VAD' then (route_s.orgn_vsl_arvl_date Between to_date('&1','DD-MON-YYYY:HH24:MI:SS')
AND to_date('&2','DD-MON-YYYY:HH24:MI:SS'))
when pstatustype='ETA' then (route_s.arrival_date Between to_date('&1','DD-MON-YYYY:HH24:MI:SS')
AND to_date('&2','DD-MON-YYYY:HH24:MI:SS'))
else NULL end)
getting an error missing parenthesis. In then it is not taking BETWEEN operator.
Please help, how i can write this code in SQL developer.
Regards,
fuko
You can't put other conditions inside the case expression clauses.
You could either switch to simpler Boolean logic:
Where (pstatustype='CTA' AND p_con.created_date Between to_date('&1','DD-MON-YYYY:HH24:MI:SS')
AND to_date('&2','DD-MON-YYYY:HH24:MI:SS'))
OR (pstatustype='VAD' AND route_s.orgn_vsl_arvl_date Between to_date('&1','DD-MON-YYYY:HH24:MI:SS')
AND to_date('&2','DD-MON-YYYY:HH24:MI:SS'))
OR (pstatustype='ETA' AND (route_s.arrival_date Between to_date('&1','DD-MON-YYYY:HH24:MI:SS')
AND to_date('&2','DD-MON-YYYY:HH24:MI:SS'))
or just pick the relevant date column in the case expression and compare that with a single date range:
Where case when pstatustype='CTA' then p_con.created_date
when pstatustype='VAD' then route_s.orgn_vsl_arvl_date
when pstatustype='ETA' then route_s.arrival_date
else null -- default anyway
end Between to_date('&1','DD-MON-YYYY:HH24:MI:SS')
AND to_date('&2','DD-MON-YYYY:HH24:MI:SS')
Related
I am having trouble with my expression. There are a lot of answers here, similar to what I am looking for as an answer but for some reason nothing seems to work. I am aware that I am concatenating different types, but I manage to convert everything to a string:
= "" & "Start Time" & strdup (25 , chr (160)) & " : " & "" & Format(Parameters!StartTime.Value , "yyyy-MM-dd HH:mm:ss") & ""
& "" & "End Time" & strdup (29 , chr (160)) & " : " & "" & Format(Parameters!EndTime.Value , "yyyy-MM-dd HH:mm:ss") & ""
& "" & "Order Number" & strdup (14 , chr (160)) & " : " & "" & Parameters!EqId.Value & ""
& "" & "Pack L" & strdup (14 , chr (160)) & " : " & "" & Parameters!PackLId.Value & ""
Did I miss something? thank you!
I am trying to overwrite specific lines in a sequential file
For example if file has:
"1"
"Kii"
"Kii"
"Kii"
"Kii"
"2"
"Troy Martinez"
"Edoy"
"Edoy"
"69"
"3"
"Snoop Dogg"
"Weed"
"President Troy"
"420"
And I have this code to overwrite
Private Sub OverWrite()
Dim Count As Integer
On Error GoTo ErrSub
LineCount = 1
Open App.Path & "\Data.txt" For Input As #1
Do While Not EOF(1)
If LineCount < ((IDCount - 1) * 5) + 1 Or LineCount >= (IDCount * 5) + 1 Then
For Count = 0 To 4
Input #1, TextTemp
FileText = FileText & """ & Text1(Count) & """ & vbCrLf
LineCount = LineCount + 1
Next Count
Else
For Count = 0 To 4
Input #1, TextTemp
FileText = FileText & """ & TextTemp & """ & vbCrLf
LineCount = LineCount + 1
Next Count
End If
Loop
Close
Open App.Path & "\Data.txt" For Output As #1
Print #1, FileText
Close
ErrSub:
Resume Next
End Sub
Assuming my IDCount is 2, the text file becomes
" & Text1(Count) & "
" & Text1(Count) & "
" & Text1(Count) & "
" & Text1(Count) & "
" & Text1(Count) & "
" & TextTemp & "
" & TextTemp & "
" & TextTemp & "
" & TextTemp & "
" & TextTemp & "
" & Text1(Count) & "
" & Text1(Count) & "
" & Text1(Count) & "
" & Text1(Count) & "
" & Text1(Count) & "
How do I fix this? Thanks
I am very noob
Edit: My Option Explicit Is
Option Explicit
Dim IDCount As Integer
Dim LineCount As Integer
Dim FileText As String
Dim TextTemp
4 quotes ("""") escape a single quote (") so:
FileText = FileText & """" & Text1(Count) & """" & vbCrLf
(chr$(34) also outputs a ")
I'm looking for a specific database error when doing a query. If the error is not found then I would like standard error handling to be used.
On Error Resume Next
db.execute(strSQL)
If db.Errors.Count > 0 Then
If InStr(db.Errors(0).Description, "IX_Code") Then
...
Else
* rethrow here *
End If
End If
Is this possible?
I tried...
On Error GoTo 0
Err.Raise 22, "Big Error", "Hello World!"
But nothing happens.
I added this code, which I found here...
For Each errLoop In db.Errors
strError = "Error #" & errLoop.Number & "<br>" & _
" " & errLoop.Description & "<br>" & _
" (Source: " & errLoop.Source & ")" & "<br>" & _
" (SQL State: " & errLoop.SQLState & ")" & "<br>" & _
" (NativeError: " & errLoop.NativeError & ")" & "<br>"
Response.Clear
Response.Write("<p>" & strError & "</p>")
Response.End
Next
Table Room
ID:1 | OFName: Room1
ID:2 | OFName: Room2
ID:3 | OFName: Room3
Table Document
ID:12 | Code:123/PA | RoomID: 1,2,3
ID:13 | Code:12/HC | RoomID: 2
ID:14 | Code:121/CA | RoomID: 2,3
ID:15 | Code:141/PC | RoomID: 1,3
And I want display like this
Room1
ID | Code
12 | 123/PA
15 | 141/PC
Room2
ID | Code
12 | 123/PA
13 | 12/HC
15 | 141/PC
I write like this but err !
<%
SQLDV = " Select ID,OFName From Room"
CREATECONNECTION()
rs.open SQLDV,ObjConn,1 ,3
While not rs.eof
response.write("" & rs(" OFName ") & "")
%>
<%
Create2ndRs()
SQLSearch = "SELECT ID,Code From Document"
ListArray = split(RoomID, ",")
For i = 0 to UBound(ListArray)-1
sqlWhere =sqlWhere & " (ListArray(i)=" & rs("ID") & ") "
Next
SQLSearch = SQLSearch & "where" & sqlWhere
rs1.open SQLSearch,ObjConn,1 ,3
While not rs1.eof
response.write("" & rs1("ID") & "","" & rs1("Code") & "")
rs1.movenext
wend
rs1.close
rs.movenext
wend
CLOSECONNECTION()%>
You have four lines of code which are just not going to work, each of these will give you its own error. You cant do this:
response.write(" & "rs(" OFName ") & "")
This should be something like (always use trim even if you don't think you need it, its just a good practice...):
response.write trim(rs("OFName"))
The way you ahve 'ListArray(i)' is inside a string. You cant do this:
sqlWhere = sqlWhere & " (ListArray(i)=" & rs("ID") & ") '"
This should be something like:
sqlWhere = sqlWhere & "(" & trim(ListArray(i)) & "=" & trim(rs("ID")) & ")"
You dont have a space after our table name and before the where, so this:
SQLSearch = SQLSearch & "where" & sqlWhere
should be
SQLSearch = SQLSearch & " where " & sqlWhere
Nor can you do this:
response.write("" & rs1("ID") & "","" & rs1("Code") & "")
I imagine you need:
response.write trim(rs1("ID")) & "," & trim(rs1("Code"))
Rather than create, and then drop a table in sqlite3, I would like to create a temporary table which is destroyed when you end your session. Is it possible to combine the commands below so the temporary table is not destroyed by the semicolon ?
set databaseName to "test.db"
set tableName to "tempTable"
do shell script ("mkdir -p ~/Documents/Databases/ ; sqlite3 ~/Documents/Databases/" & databaseName & " \"create table if not exists " & tableName & "(First, Last); \"")
do shell script ("sqlite3 ~/Documents/Databases/" & databaseName & " \"insert into " & tableName & " (First, Last) values('John', 'Doe'); \"")
How would I implement this version of it?
set databaseName to "test.db"
set tableName to "tempTable"
do shell script ("mkdir -p ~/Documents/Databases/ ; sqlite3 ~/Documents/Databases/" & databaseName & " \"create temp table " & tableName & "(First, Last); \"")
do shell script ("sqlite3 ~/Documents/Databases/" & databaseName & " \"insert into " & tableName & " (First, Last) values('John', 'Doe'); \"")
SQLite accepts semicolon-separated statements itself.
do shell script ("sqlite3 ~/Documents/Databases/" & databaseName & " \" & ¬
"create temp table " & tableName & " (First, Last); " & ¬
"insert into " & tableName & " (First, Last) values('John', 'Doe'); " & ¬
" -- other stuff here --" & ¬
"select * from " & tableName & ";\"")
At some point it becomes easier to write it out as a separate script or possibly a here document than to build up a single huge do shell script, though.