Syntax error: Expected end of input but got keyword IF - sql

Sample
I tried to run a query with 2 IF keyword. I ma getting a syntex error in the second IF clause. How can I keep the second IF different from the first one.

Next time please give your statement as text, not a screenshot.
You need a comma separating temperature and windspeed. After correcting that, next error will be in wdsp, do you want it as provided or cast to float64?

Related

Pyspark: mismatched input ... expecting EOF

I want to add a column to a data frame and depending on whether a certain value appears in the source json, the value of the column should be the value from the source or null.
My code looks like this:
withColumn("STATUS_BIT", expr("case when 'statusBit:' in jsonDF.schema.simpleString() then statusBit else None end"))
When I run this, I am getting "mismatched input ''statusBit:'' expecting {< EOF >, '-'} .
Am I doing something wrong with the quotation marks?
When I try
withColumn("STATUS_BIT", expr("case when \'statusBit:\' in jsonDF.schema.simpleString() then statusBit else None end"))
I get the exact same error.
Trying the whole thing without expr but as a simple when, triggers the error "condition should be a Column". Running 'statusBit:' in jsonDF.schema.simpleString() by itself returns True with the testdata I am using, but somehow I cant integrate it into the dataframe transformation.Thanks a lot for your help in advance.
edit: Applying the solution provided by PLTC has helped a lot, but I am still struggling to get this solution implemented in the when clause:
I try
.withColumn("STATUS_BIT", when(lit(df.schema.simplestring()).contains("statusBit") is True, col(statusBit)).otherwise(None))
but it tells me "condition should be a Column". So I added an extra colum called SCHEMA, which is equal to lit(df.schema.simpleString) and I used this column in the condition:
.withColumn("STATUS_BIT", when(col("SCHEMA").contains("statusBit"), col("StatusBit")).otherwise(None)
The problem is that if I run this with test data that does not contain "statusBit", I get the error "No such struct field statusBit in ...", which is obviously the opposite of what I wanted to achieve
jsonDF.schema.simpleString() is Python variable, you can use it in Python way
from pyspark.sql import functions as F
df.withColumn("STATUS_BIT", F.lit(df.schema.simpleString()).contains('statusBit:'))

How to return first letter of a word in Access

I have been trying to return the first letter of a last name in Access.
I tried this in a query but it shows an error message.
In my table I have a field called lastName.
When I make a new query and open the expression builder I use the following expression:
Example: Left([lastName],1)
It shows the error that it is invalid.
How do I make this work?
Microsoft's Help on String Functions shows that you should be using the following format:
=Left([SerialNumber],2)
If [SerialNumber] is “CD234”, the result is “CD”.
I took a quick look at a few different languages, and they all showed the same format. None of them used a semicolon (;) in place of a comma (,).

sql remove date and time stamp from string

Do any of you awesome DBA fellows know how to remove both the Date and Time stamp from an SQL string?
For example, I have a string that has this:
"2014-04-17 15:38:53.2389 Unexpected Failure System.ServiceModel.FaultException: Unexpected Failure"
I want to remove the "2014-04-17 15:38:53.2389" and just be left with this:
"Unexpected Failure System.ServiceModel.FaultException: Unexpected Failure"
I can get it to work using SUBSTRING
SUBSTRING(CAST([stacktrace] AS NVARCHAR(500)),25 ,LEN(CAST([stacktrace] AS NVARCHAR(500)))) as stackTrace
But this isn't very elegant and could cause problems for string that don't have dates at the start.
I can find ways to remove the TimeStamp or to remove the Date, but I can't find a way to remove both.
Any help would be much appreciated.
Thanks
I don't know the exact code, but: It should be possible to filter the string according to the first alphabetic letter in the string.
at least provide a generic format of your error like you are going to get date and timestamp or just time stamp or some text your error always start with
You can use as following:
check if it is date at start and design the substring accordingly under if-else
select isdate(convert(varchar(10),'2014-04-17 15:38:53.100',111))
possibly you can use as
if (select isdate(convert(varchar(10),<use substring to get first 25 values>,111)))=1
then <design substring to remove and use data>
else
<use as-is>

Data output syntax in Webi XI3.1

I am trying to duplicate a detail object from Desktop to its Webi equivalent.
I am familiar with the syntax differences, i.e. using semicolons instead of commas and using [] rather than <> to enclose references to other dimensions/measures/detail objects.
Given the working formula from the Deski report:
=ToDate(7+"/1/"+<Current FY>-1 ,"mm/dd/yyyy")
I tried to convert this using the syntax I know from Webi:
=ToDate(7+"/1/"+[Current FY]-1 ; "mm/dd/yyyy")
I faced the error message
The expression or sub-expression at position 8 in the '-' function uses an invalid data type
I am guessing this has something to do with trying to convert a date datatype into an integer in order to subtract "1." However, I do not know what kind of function this requires.
Thanks in advance!

What is wrong with this SQLite3 statement?

I have written this SQLite statement and I am getting syntax error on the following line:
update List SET number = (CASE WHEN number>=3 then number++ WHEN number=1 then 3 ELSE number END) WHERE listKey=3;
The error is:
SQL error: near "WHEN": syntax error
I tried various versions, adding braces at places and all, but can't figure out the error. Can anyone please help me with this?
If SQLite uses "++" syntax, I've never seen it. Try then number + 1 instead.