I need to create a computed column in SAS with the combination of the string 'ULPDT_' and the result from the today() function. so that my result looks like this: ULPDT_20190101. Here is my non-functional code for the advanced expression:
t1.SourceFile='ULPDT_'||PUT(today(), yyddmmn8.)
year-day-month, YYYYDDMM, is not a normal representation for date, you might actually want year-month-day YYYYMMDD
t1 is indicative of an EG generated join wherein the t1 is a table alias. If you are editing the code of a join node, and the problematic statement is part of a select clause, the correct SQL syntax might be
'ULPDT_'||PUT(today(), yymmddn8.) as t1.SourceFile
Hand coded example (versus EG visual join):
proc sql;
create table x as
select
'ULPDT_'||PUT(today(), yymmddn8.) as SourceFile
from
sashelp.class(obs=1)
;
Related
Context: I've a data flow that extracts data from SQL DB, when data comes is just one column with a string separated by tab, in order to manipulate the data properly, I've tried to separate every single column with its corresponding data:
Firstly, to 'rebuild' the table properly I used a 'Derived Column' activity replacing tab with semicolons instead (1)
dropLeft(regexReplace(regexReplace(regexReplace(descripcion,[\t],';'),[\n],';'),[\r],';'),1)
So, after that use 'split()' function to get an array and build the columns (2)
split(descripcion, ';')
Problem: When I try to use 'Flatten' activity (as here https://learn.microsoft.com/en-us/azure/data-factory/data-flow-flatten), is just not working and data flow throws me just one column or if I add an additional column in the 'Flatten' activity I just get another column with the same data that the first one:
Expected output:
column2
column1
column3
2000017
ENVASE CORONA CLARA 24/355 ML GRAB
PC13
2004297
ENVASE V FAM GRAB 12/940 ML USADO
PC15
Could you say me what i'm doing wrong, guys? thanks by the way.
You can use the derived column activity itself, try as below.
After the first derived column, what you have is a string array which can just be split again using derived schema modifier.
Where firstc represent the source column equivalent to your column descripcion
Column1: split(firstc, ';')[1]
Column2: split(firstc, ';')[2]
Column3: split(firstc, ';')[3]
Optionally you can select the columns you need to write to SQL sink
I'm struggling with probably the simplest thing. How do I filter my data using a where clause in Excel 2016, ODBC sql database source.
I'm new to Excel 2016, I used to just modify the SQL Command via the odbc properties. Now i can't even see the SQL command when I create the odbc.
So from just playing around. I gathered that there is now a series of "Applied Steps", but I struggle to find where I can find how to limit the rows to a date range. (I don't want to display the date because I'm aggregating by inventory type) But there must be somewhere I can say return only for date '2020-05-01' for example. (where date = '2020-05-01')
the next steps will then be making that a dynamic parameter so I can have some sort of input when the data refresh.
Any tips?
The SQL statement is greyed out
Right clicking a step -> view native SQL will gray out when that step cannot be query folded. Previous steps are still viewable.
You can find the sql query and server name if you choose advanced editor -- which displays all steps in one editor.
native sql
If you want raw sql, import the table as a new connection and paste your query into that box.
note: [] in powerquery is a Record literal.
// indented for readability
let
Source = Sql.Database("server", "dbo"),
// using parameterized queries
RawSQL = "SELECT * FROM users as
WHERE EnglishMonthName=#MonthName
AND
EnglishDayNameOfWeek=#DayName",
TableName = Value.NativeQuery(
Source, RawSQL
[
MonthName="March",
DayName="Tuesday"
]
)
in
TableName
I don't want to display the date because I'm aggregating by inventory type
Using the UI, you would import the table keeping the date column. Filter rows. Then choose remove column as your last step. Your model will not display removed columns.
Where clause in PowerQuery aka: Get Data
Where is the function Table.SelectRows The UI will generate the code for you
Right click your date column -> filter -> date/time -> equals
If you want 2020/05/09 It generates:
= Table.SelectRows(#"Source Table", each [Date] = #date(2020, 5, 9))
You may use multiple conditions, like a date range
= Table.SelectRows(#"Table Name", each
[Date] >= #date(2020, 5, 9) and
[Date] <= #date(2020, 6, 1)
)
We have a field in Access called 'DATE', in which the date is recorded, but is of the type Text.
Now, if we want to do a search, how is it possible with 'Between' statement ?
I use this code but it does not answer
ADOQuery1.SQL.Text:= 'Select * From tst Where 1=1';
ADOQuery1.SQL.Add(' And Date1 Between ' +
Date1.Format('yyyy/mm/dd',
Date1.Date) + ' And ' + Date2.Format('yyyy/mm/dd', Date2.Date));
I think I need to convert string to date or number, but I do not know how
As you say the field is text so values used in any where critera are expected to be text - i.e. strings. Your encoded date values are not represented in the resulting SQL as a string, but as date literals, e.g.:
select * From tst Where 1=1
and Date1 Between 2018/01/01 and 2018/01/31
You need to use strings as the limits on your query (and also bear in mind that dates are quote delimited in SQL anyway, even when expressed as literals):
select * From tst Where 1=1
and Date1 between '2018/01/01' and '2018/01/31'
Assuming that the representation of the dates in your field are reliably consistent, this should work, thanks to the y-m-d ordering of your date components in that representation.
A small modification to your SQL construction code to include quotes around the encoded date values should do the trick:
ADOQuery1.SQL.Text:= 'Select * From tst Where 1=1';
ADOQuery1.SQL.Add(' And Date1 Between ''' +
Date1.Format('yyyy/mm/dd', Date1.Date) + ''' And ''' +
Date2.Format('yyyy/mm/dd', Date2.Date) + '''');
This alternative approach to building the SQL might make it a little clearer exactly what is going on:
// Obtain string representations of Date values
sDateFrom := Date1.Format('yyyy/mm/dd', Date1.Date);
sDateTo := Date2.Format('yyyy/mm/dd', Date2.Date);
// Build SQL using string representations of dates in criteria
ADOQuery1.SQL.Text:= 'Select * From tst Where 1=1';
ADOQuery1.SQL.Add(Format(' and Date1 between ''%s'' and ''%s''', [sFromDate, sToDate]));
If you are in a position to change the implementation details of the database in your application, you should seriously consider using an appropriate date or date/time type for such columns which could simplify things when dealing with those columns and needing to work with them as dates or date/times, not least in then being able to use date/time related functions of your SQL engine directly on such columns, for example.
Also worth mentioning is that building SQL using string concatenation can make your code vulnerable to SQL Injection attacks. The specifics of this case mean that the code here is not vulnerable since the values involved are constrained to formatted date values, but this is a consideration and generally speaking parameterized queries are safer and can be significantly more efficient, especially where a query is re-used (executed several times) with only variations in the parameter values.
I am a beginner in cognos 10. I want to know how to get the value of a prompt from a Query1 and use it on Query2. My requirement is I want a prompt to ask the year for which I want the data in Query1 and in Query2 I want the data relevant to the previous year to that entered in the prompt. How to do that?
You can use the same parameter (tied to the prompt) in filters in both queries. If your parameter is Parameter1 and contains a four-digit year, and your data item in your filter is [Year] then your Query1 filter might look like this:
[Year] = ?Parameter1?
Your Query2 filter would be:
[Year] = ?Parameter1? - 1
Depending on your data source you may have to cast the string parameter to an integer before doing the subtraction though most SQL implementations will implicitly convert the string parameter to an integer for you.
I am trying to read in a table called operations that looks like so
"id";"name";
"1";"LASER CUTTING";
"2";"DEBURR";
"3";"MACHINING";
"4";"BENDING";
"5";"PEM";
"6";"WELDING";
"7";"PAINT PREPARATION";
"8";"PAINTING";
"9";"SILKSCREEN PREPARATION";
"10";"SILKSCREEN";
"11";"ASSEMBLY - PACKAGING";
"12";"LASER PREP";
I want to have a column in a worksheet that gets the appropriate name based on value of an operation_id column in another worksheet.
How do I lookup a particular cell in another worksheet dependent on the value of a cell?
Example
userid, operation_id, operation_name
bob, 3, MACHINING
You should look at the DGET(database,field,criteria) function, reference here.
Or you can use this worksheet function:
VLOOKUP(cellWithID, Sheet2!A1:B13, 2, FALSE)
where cellWithID is the cell with the ID value you want to use.
Maybe the Lookup() function would work better for you.
http://www.techonthenet.com/excel/formulas/lookup.php
Basing off this: "What I really want to do is just lookup the name for an operation without having to run a sql query every time or have an ugly huge if statement in every cell."
I guess what confuses me here is why you don't just use a join. You can always join that table as a lookup to whatever your sql statement is;
select operations.name, tableA.* from tableA
left outer join operations on operations.id = tableA.operationid
If you wanted to, you could functionize this; not recommended. Subqueries are generally speaking bad news. However,
create function dbo.LookupOperationName
(
#id int
)
returns varchar(100)
as
declare #returnvalue varchar(100)
select #returnvalue = name from Operations where id = #id
return #returnValue
would do the trick. Then you could:
select tablea.*,LookupOperationName(operationid) from tablea
Again, remember that your join example is much more performant. You could also create a view that had the join, and use the view in place of the table.... all kinds of things.