I'm trying to edit this code to be dynamic as I'm going to schedule it to run.
Normally I would input the date in the where statement as 'YYYY-MM-DD' and so to make it dynamic I changed it to DATE(). I'm not erroring out, but I'm also not pulling data. I just need help with format and my google searching isn't helping.
PROC SQL;
CONNECT TO Hadoop (server=disregard this top part);
CREATE TABLE raw_daily_fcast AS SELECT * FROM connection to Hadoop(
SELECT DISTINCT
a.RUN_DATE,
a.SCHEDSHIPDATE,
a.SOURCE,
a.DEST ,
a.ITEM,
b.U_OPSTUDY,
a.QTY,
c.case_pack_qty
FROM CSO.RECSHIP a
LEFT JOIN CSO.UDT_ITEMPARAM b
ON a.ITEM = b.ITEM
LEFT JOIN SCM.DIM_PROD_PLN c
ON a.ITEM = c.PLN_NBR
WHERE a.RUN_DATE = DATE()
AND a.SOURCE IN ('88001', '88003', '88004', '88006', '88008', '88010', '88011', '88012',
'88017', '88018', '88024', '88035', '88040', '88041', '88042', '88047')
);
DISCONNECT FROM Hadoop;
QUIT;
When RUN_DATE is a string you can generate the current date string in-line on the SAS side
WHERE a.RUN_DATE = %str(%')%sysfunc(date(),yymmdd10.)%str(%')
AND ...
or
WHERE a.RUN_DATE = %sysfunc(quote(%sysfunc(date(),yymmdd10.),%str(%')))
AND ...
For the case of RUN_DATE being a string containing DATE9 formatted values, change the yymmdd10. to date9.
change:
WHERE a.RUN_DATE = DATE()
to:
WHERE a.RUN_DATE = PUT(date(), YYMMDD10.) AS date
Related
I have created a view in SQL Plus as follows.
CREATE VIEW jour_cond
AS
SELECT c.nom, c.prenom FROM Conducteur c
JOIN Affectation a ON c.Id_conducteur = a.Id_conducteur
JOIN Trajet t ON a.ID_Trajet = t.ID_Trajet
WHERE t.date_depart = sysdate;
And I have added a value which is the date of today to the column date_depart. But when I call for this view it doesn't show the result. Could you please help?
I figured out that 'sysdate' is working just when it is called from dual. So for the last line I should have written ;
'WHERE t.date_depart = (select sysdate from dual)'
I have expression with db_link to MS SQL:
select b."Str" as "State" ,a."_Fld9059" as "Date" from
"_InfoRg9050"#SQLSERVER.UISLAB.COM a INNER JOIN
"EnumTexts"#SQLSERVER.UISLAB.COM b
on a."_Fld9052RRef" = b."_IDRRef"
where a."_Fld10998" = '1104000009' and
a."_Fld10998" = to_date(max(a."_Fld9059"),'dd.mm.yyyy')
order by a."_Fld9059" desc;
I want to upload value with maximum date. Can anybody help me ?
When I run this query I get ORA-00934 error.
The immediate cause of the error you are getting is that MAX() appears in the WHERE clause. One possible workaround, which might be what you intended, would be to use a subquery in the WHERE clause to identify the maximum date:
SELECT b.Str AS State,
a._Fld9059 AS Date
FROM _InfoRg9050 a
INNER JOIN EnumTexts b
ON a._Fld9052RRef = b._IDRRef
WHERE a._Fld10998 = '1104000009' AND
a._Fld10998 = (SELECT MAX(TO_DATE(_Fld9059, 'dd.mm.yyyy')) FROM _InfoRg9050)
ORDER BY a._Fld9059 DESC
However, it is not clear why you are comparing _InfoRg9050._Fld10998 to both the string '1104000009' and a date. You will need to resolve this on your own I believe to get a meaningful result.
Thank you for your help. I got it.
SELECT b."Str" AS "State"
FROM "_InfoRg9050"#SQLSERVER.UISLAB.COM a
INNER JOIN "EnumTexts"#SQLSERVER.UISLAB.COM b
ON a."_Fld9052RRef" = b."_IDRRef"
WHERE a."_Fld10998" = '1104000009' AND
a."_Fld9059" = (select MAX(a."_Fld9059") from "_InfoRg9050"#SQLSERVER.UISLAB.COM a
INNER JOIN "EnumTexts"#SQLSERVER.UISLAB.COM b
on a."_Fld9052RRef" = b."_IDRRef"
where a."_Fld10998" = '1104000009')
ORDER BY a."_Fld9059" DESC
DECLARE #items table (
pfid varchar(8),
timestart datetime,
timeend datetime
)
insert INTO #items(pfid,timestart,timeend)
VALUES('123456','12:00 AM','3:00 AM')
,('987654', '2:00 AM', '4:00 PM')
,('492384', '3:00 PM', '9:00 PM')
SELECT * FROM #items a
INNER JOIN #items b
ON a.timestart < b.timeend
AND b.timestart < a.timeend
AND a.pfid != b.pfid
I need the select statement above converted to LINQ. In my code, I am working with a DataTable, named 'dt'. My table has three columns just like in the example above, exact same names and populated with this data.
I am struggling to create a LINQ query that will query my DataTable in the same fashion my SQL query is working with the temp table above. Please assist. Thanks in advance!
something in the line of...i didn't test this but you may have to do Datetime.Parse etc if needed...
(from r1 in dt.Rows.OfType<DataRow>()
from r2 in dt.Rows.OfType<DataRow>()
where r1["timestart"] < r2["timeend"] && r2["timestart"] < r1["timeend"] && r1["pfid"] != r2["pfid"]
select new {R1=r1, R2=r2})
I have the following query in oracle. I want to convert it to PostgreSQL form. Could someone help me out in this,
SELECT user_id, user_name, reports_to, position
FROM pr_operators
START WITH reports_to = 'dpercival'
CONNECT BY PRIOR user_id = reports_to;
A something like this should work for you (SQL Fiddle):
WITH RECURSIVE q AS (
SELECT po.user_id,po.user_name,po.reports_to,po.position
FROM pr_operators po
WHERE po.reports_to = 'dpercival'
UNION ALL
SELECT po.user_id,po.user_name,po.reports_to,po.position
FROM pr_operators po
JOIN q ON q.user_id=po.reports_to
)
SELECT * FROM q;
You can read more on recursive CTE's in the docs.
Note: your design looks strange -- reports_to contains string literals, yet it is being comapred with user_id which typicaly is of type integer.
I've got the following Update but I don't want to copy the values manually.
I prefer to extract them using a query.
Should I use PL/SQL or is there an SQL formulation?
The query that I use to obtain the values I've copied manually into the update is not key preserving ("Key-preserved table concept in join view").
UPDATE wkf_cronologia
SET swkf_stato_workflow_id = 'o3gE1tlSdcDIC6FF',
swkf_data_ini = TO_TIMESTAMP ('19-06-2010 18:28:10,556000000','DD-MM-RRRR HH24:MI:SS,FF'),
swkf_versione = 0,
SPWKF_STATO_PUBBLICO_ID = '*1UNICOO',
SPWKF_DATA_INI = TO_TIMESTAMP ('01-01-0001 00:00:00,000000000', 'DD-MM-RRRR HH24:MI:SS,FF'),
SPWKF_VERSIONE = 0
WHERE wkfc_cronologia_id = 'ApAJ0qCudNphjLxj';
You can use a subquery:
UPDATE wkf_cronologia
SET (swkf_stato_workflow_id,
swkf_data_ini,
swkf_versione,
SPWKF_STATO_PUBBLICO_ID,
SPWKF_DATA_INI,
SPWKF_VERSIONE) = (select a,b,0,c,d,e
from another_table
where something=wkf_cronologia.swkf_stato_workflow_id)
WHERE swkf_versione is null;