SQL error: "date format picture ends before converting entire input string" - sql

I receive the error in the header when I run this case when statement in my query. Normally this error should be resulted from missing to_date function but I believe I have everything needed, but don't know why I am receiving this really. Any help is much appreciated!
case when week=to_date('25/06/2017','YYYY/MM/DD') then 26
when week=to_date('02/07/2017','YYYY/MM/DD') then 27
when week=to_date('09/07/2017','YYYY/MM/DD') then 28
when week=to_date('16/07/2017','YYYY/MM/DD') then 29
when week=to_date('23/07/2017','YYYY/MM/DD') then 30
when week=to_date('30/07/2017','YYYY/MM/DD') then 31
when week=to_date('06/08/2017','YYYY/MM/DD') then 32
when week=to_date('13/08/2017','YYYY/MM/DD') then 33
when week=to_date('20/08/2017','YYYY/MM/DD') then 34
when week=to_date('27/08/2017','YYYY/MM/DD') then 35
when week=to_date('03/09/2017','YYYY/MM/DD') then 36
when week=to_date('10/09/2017','YYYY/MM/DD') then 37
when week=to_date('17/09/2017','YYYY/MM/DD') then 38
when week=to_date('24/09/2017','YYYY/MM/DD') then 39
when week=to_date('01/10/2017','YYYY/MM/DD') then 40
when week=to_date('08/10/2017','YYYY/MM/DD') then 41
when week=to_date('15/10/2017','YYYY/MM/DD') then 42
when week=to_date('22/10/2017','YYYY/MM/DD') then 43
when week=to_date('29/10/2017','YYYY/MM/DD') then 44
when week=to_date('05/11/2017','YYYY/MM/DD') then 45
when week=to_date('12/11/2017','YYYY/MM/DD') then 46
when week=to_date('19/11/2017','YYYY/MM/DD') then 47
when week=to_date('26/11/2017','YYYY/MM/DD') then 48
when week=to_date('03/12/2017','YYYY/MM/DD') then 49
when week=to_date('10/12/2017','YYYY/MM/DD') then 50
when week=to_date('17/12/2017','YYYY/MM/DD') then 51
when week=to_date('24/12/2017','YYYY/MM/DD') then 52
else 0 end as week,

Çağdaş, make your format like this :
to_date('25/06/2017','DD/MM/YYYY')
instead of to_date('25/06/2017','YYYY/MM/DD') and so on like this for the others. Since the order in date formatting is wrong.

The format is wrong.
You can use to_date('25/06/2017','DD/MM/YYYY') in all the expressions.

Instead of hardcoding so many times, you can use TO_CHAR function to extract Week of the year from a given date.
In your case you can use
SELECT TO_CHAR(week,'WW') from table_name;

Related

translate Dataframe using crosswalk in julia

I have a very large dataframe (original_df) with columns of codes
14 15
21 22
18 16
And a second dataframe (crosswalk) which maps 'old_codes' to 'new_codes'
14 104
15 105
16 106
18 108
21 201
22 202
Of course, the resultant df (resultant_df) that I would like would have values:
104 105
201 202
108 106
I am aware of two ways to accomplish this. First, I could iterate through each code in original_df, find the code in crosswalk, then rewrite the corresponding cell in original_df with the translated code from crosswalk. The faster and more natural option would be to leftjoin() each column of original_df on 'old_codes'. Unfortunately, it seems I have to do this separately for each column, and then delete each column after its conversion column has been created -- this feels unnecessarily complicated. Is there a simpler way to convert all of original_df at once using the crosswalk?
You can do the following (I am using column numbers as you have not provided column names):
d = Dict(crosswalk[!, 1] .=> crosswalk[!, 2])
resultant_df = select(original_df, [i => ByRow(x -> d[x]) for i in 1:ncol(original_df)], renamecols=false)

u-sql: filtering out empty// Null strings (microsoft academic graph)

I am new to u-sql of azure datalake analytics.
I want to do what I think is a very simple operations but ran into trouble.
Basically: I want to create a query which ignore empty string.
using it in select works, but not in WHERE statement.
Below the statement I am making and the cryptic error I get
JOB
#xsel_res_1 =
EXTRACT
x_paper_id long,
x_Rank uint,
x_doi string,
x_doc_type string,
x_paper_title string,
x_original_title string,
x_book_title string,
x_paper_year int,
x_paper_date DateTime?,
x_publisher string,
x_journal_id long?,
x_conference_series_id long?,
x_conference_instance_id long?,
x_volume string,
x_issue string,
x_first_page string,
x_last_page string,
x_reference_count long,
x_citation_count long?,
x_estimated_citation int?
FROM #"adl://xmag.azuredatalakestore.net/graph/2018-02-02/Papers.txt"
USING Extractors.Tsv()
;
#xsel_res_2 =
SELECT
x_paper_id AS x_paper_id,
x_doi.ToLower() AS x_doi,
x_doi.Length AS x_doi_length
FROM #xsel_res_1
WHERE NOT string.IsNullOrEmpty(x_doi)
;
#xsel_res_3 =
SELECT
*
FROM #xsel_res_2
SAMPLE ANY (5)
;
OUTPUT #xsel_res_3
TO #"/graph/2018-02-02/x_output/x_papers_x6.tsv"
USING Outputters.Tsv();
THE ERROR
Vertex failed
Vertex failure triggered quick job abort. Vertex failed: SV1_Extract[0][1] with error: Vertex user code error.
VertexFailedFast: Vertex failed with a fail-fast error
E_RUNTIME_USER_EXTRACT_ROW_ERROR: Error occurred while extracting row after processing 10 record(s) in the vertex' input split. Column index: 5, column name: 'x_original_title'.
E_RUNTIME_USER_EXTRACT_EXTRACT_INVALID_CHARACTER_AFTER_QUOTED_FIELD: Invalid character following the ending quote character in a quoted field.
Row selected
Component
RUNTIME
Message
Invalid character following the ending quote character in a quoted field.
Resolution
Column should be fully surrounded with double-quotes and double-quotes within the field escaped as two double-quotes.
Description
Invalid character is detected following the ending quote character in a quoted field. A column delimiter, row delimiter or EOF is expected. This error can occur if double-quotes within the field are not correctly escaped as two double-quotes.
Details
Row Delimiter: 0x0
Column Delimiter: 0x9
HEX: 61 76 6E 69 20 74 65 72 6D 69 6E 20 75 20 70 6F 76 61 6C 6A 73 6B 6F 6A 20 6C 69 73 74 69 6E 69 20 69 20 6E 61 74 70 69 73 75 20 67 20 31 31 38 35 09 22 50 6F 20 6B 6F 6E 63 75 22 ### 20 28 73 74 61 72 69 20 68 72
UPDATE
BY the way, the operations work on other datasets, so the problem is not the syntax as far as I can tell
//Define schema of file, must map all columns
#searchlog =
EXTRACT UserId int,
Start DateTime,
Region string,
Query string,
Duration int,
Urls string,
ClickedUrls string
FROM #"/Samples/Data/SearchLog.tsv"
USING Extractors.Tsv();
#searchlog_1 =
SELECT * FROM #searchlog
WHERE NOT string.IsNullOrEmpty(ClickedUrls );
OUTPUT #searchlog_1
TO #"/Samples/Output/SearchLog_output_x1.tsv"
USING Outputters.Tsv();
This is an unfortunate error display for this case.
Assuming text is utf-8, you can use a site like www.hexutf8.com to convert the hex to:
avni termin u povaljskoj listini natpisu g 1185 "Po koncu" (Stari hr
It looks like the input row contains at least one " character that is not properly escaped. It should look like this:
avni termin u povaljskoj listini natpisu g 1185 ""Po koncu"" (Stari hr
#Saveenr's answer assumes that the values in your file are all quoted. Alternatively, if they are not quoted (and do not contain your column separator as values), then setting Extractors.Tsv(quoting:false) could help as well.

Microsoft Internet Controls

I am using:
IE.ExecWB 17, 0 '// SelectAll
IE.ExecWB 12, 2 '// Copy selection
in an Excel VBA program successfully, but I am having trouble finding a reference for all ExecWB methods. Can anyone point me in the right direction?
Here is something from my database. I doubt you will find this on the web anymore. I will be surprised if you do...
ExecWB syntax is as follows:
object.ExecWB nCmdID, nCmdExecOpt, [pvaIn], [pvaOut]
The ExecWB method requires an OLE Command ID to be passed in to identify the command to execute. This value nCmdID is of type Long. The nCmdExecOpt parameter represents the value for the command execution option. Together, these values instruct the control as to what supported command to execute and what degree of user prompting should occur.
The last two parameters pvaIn and paOut are optional and is usually set to either NULL or an empty string.
Here is a complete list for the 1st parameter
OLECMDID_OPEN 1 Open
OLECMDID_NEW 2 Create a new document
OLECMDID_SAVE 3 Preservation
OLECMDID_SAVEAS 4 Save as
OLECMDID_SAVECOPYAS 5  
OLECMDID_PRINT 6 Print
OLECMDID_PRINTPREVIEW 7 Print preview
OLECMDID_PAGESETUP 8 Page setup
OLECMDID_SPELL 9 The spelling check
OLECMDID_PROPERTIES 10 Attribute
OLECMDID_CUT 11 Shear
OLECMDID_COPY 12 Replication
OLECMDID_PASTE 13 Paste
OLECMDID_PASTESPECIAL 14 Paste special
OLECMDID_UNDO 15 Revoke
OLECMDID_REDO 16 Repeat
OLECMDID_SELECTALL 17 Select all
OLECMDID_CLEARSELECTION 18 Clear selection
OLECMDID_ZOOM 19
OLECMDID_GETZOOMRANGE 20
OLECMDID_UPDATECOMMANDS 21 The update command
OLECMDID_REFRESH 22 Refresh
OLECMDID_STOP 23 Stop it
OLECMDID_HIDETOOLBARS 24 Hide toolbar
OLECMDID_SETPROGRESSMAX 25 Progress bar maximum
OLECMDID_SETPROGRESSPOS 26 Progress bar position
OLECMDID_SETPROGRESSTEXT 27 Progress bar text
OLECMDID_SETTITLE 28 Set the title
OLECMDID_SETDOWNLOADSTATE 29 Set download status
OLECMDID_STOPDOWNLOAD 30 Stop downloading
OLECMDID_ONTOOLBARACTIVATED 31
OLECMDID_FIND 32 Search
OLECMDID_DELETE 33 Delete
OLECMDID_HTTPEQUIV 34
OLECMDID_HTTPEQUIV_DONE 35
OLECMDID_ENABLE_INTERACTION 36 Allow the interaction
OLECMDID_ONUNLOAD 37 When uninstall
OLECMDID_PROPERTYBAG2 38
OLECMDID_PREREFRESH 39
OLECMDID_SHOWSCRIPTERROR 40
OLECMDID_SHOWMESSAGE 41 Display a message
OLECMDID_SHOWFIND 42 Display search
OLECMDID_SHOWPAGESETUP 43 Display page setup
OLECMDID_SHOWPRINT 44 Display and printing
OLECMDID_CLOSE 45 Close
OLECMDID_ALLOWUILESSSAVEAS 46
OLECMDID_DONTDOWNLOADCSS 47
OLECMDID_UPDATEPAGESTATUS 48
OLECMDID_PRINT2 49 Print 2
OLECMDID_PRINTPREVIEW2 50 Print preview
OLECMDID_SETPRINTTEMPLATE 51 Set the print template
OLECMDID_GETPRINTTEMPLATE 52 Get a print template
OLECMDID_PAGEACTIONBLOCKED 55
OLECMDID_PAGEACTIONUIQUERY 56
OLECMDID_FOCUSVIEWCONTROLS 57
OLECMDID_FOCUSVIEWCONTROLSQUERY 58
OLECMDID_SHOWPAGEACTIONMENU 59
OLECMDID_ADDTRAVELENTRY 60
OLECMDID_UPDATETRAVELENTRY 61
OLECMDID_UPDATEBACKFORWARDSTATE 62
OLECMDID_OPTICAL_ZOOM 63
OLECMDID_OPTICAL_GETZOOMRANGE 64
OLECMDID_WINDOWSTATECHANGED 65 windows status change
Here is a complete list for the 2nd parameter
OLECMDEXECOPT_DODEFAULT 0 Default parameters
OLECMDEXECOPT_PROMPTUSER 1 Prompt the user, namely the pop-up dialog box
LECMDEXECOPT_DONTPROMPTUSER 2 User is not prompted
OLECMDEXECOPT_SHOWHELP 3 displays help
Examples
WebBrowser.ExecWB(6,1) '<~~ Print
WebBrowser.ExecWB(7,1) '<~~ Print preview
WebBrowser.ExecWB(8,1) '<~~ The printed page setup

SQL Transform/Pivot

I'm fairly new to this, and have done a lot of searching, but I'm not even 100% sure what exactly to search for, except I know I need to use Transform.
I basically need this:
Column A Column B
Total 184
Half 20
Some 25
None 30
Total 52
Half 25
Some 16
None 86
To become:
Total Half Some None
184 20 25 30
52 25 16 86
Any help would be amazing, it's the last part of a query, then it's done.
Thanks :)
The answer ended up being something like this. Don't do it with the Query Wizard, it won't work out very well. This is Access 2010.
TRANSFORM First(Table.ColumnB) AS FirstOfColumnB
SELECT Table.Columns
FROM Table
GROUP BY Table.Columns
PIVOT Table.ColumnA;

How to recalculate measure based on filtered values

I am a newbie in SSAS, I have encountered a minor issues in cube and I cant solve it in many days
Please help me this, I very appreciate your ideas.
My cube has a measure that shows the percentage.
The percentage does not displays correctly when we use filter.
For example:
*** Without filter any dimensions, it is correct
Age Percentage
15 - 24 11.64%
25 - 24 24.21%
35 - 44 24.03%
45 - 54 20.17%
55 - 64 12.92%
65+ 6.66%
Do not know 0.38%
Grand Total 100.00%
*** With filter Gender=Male (or any dimensions), it likes this.
Age Percentage
15 - 24 4.72%
25 - 24 13.55%
35 - 44 15.87%
45 - 54 13.52%
55 - 64 8.07%
65+ 3.66%
Do not know 0.18%
Grand Total 59.58%
what I expect that it should be 100% in Grand Total and the percentage of each category must be recalculated.
Please help me !!!