Oracle Sql developer how to display null foreign key - oracle

I am doing Oracle database project which called "Theatre booking system".
I am trying to display discounted price through Customer_Concession and Member_Concession.
Null-able foreign keys are bookingId, cconcessionId, and mconcessionId in Ticket table.
I want to display all ticket even one of id is not exist.
How can I write the SQL?
Could you help me?
Thanks.
SELECT t.ticketId, pro.name "Production name", PRICE.LEVELID "Price level",
Price.price "Price", (Price.price - ccons.discountPrice - mcons.discountPrice)
"Discounted Price", t.seatNo "Seat", t.rowNo "Row", t.block "Block",
per.performance_date "Performance date", per.start_time "Start time",
per.end_time "End time", t.availability "Availability"
FROM Ticket t, Production pro, Performance per, Price, Price_level,
Booking, Customer, Customer_Concession ccons, Member_concession mcons
WHERE t.performanceid = per.performanceid AND
t.PRODUCTIONID = Price.PRODUCTIONID AND
t.levelId = Price.levelId AND
Price.PRODUCTIONID = pro.PRODUCTIONID AND
Price.levelId = Price_level.levelId AND
t.bookingId = Booking.bookingId AND
Booking.customerId = Customer.customerId AND
ccons.cconcessionId = t.cconcessionId AND
mcons.mconcessionId = t.mconcessionId
ORDER BY t.ticketId

What you are looking for is called LEFT OUTER JOIN.
for more info, visit this site: http://www.oreillynet.com/network/2002/04/23/fulljoin.html

Try...
WHERE t.performanceid = per.performanceid AND
t.PRODUCTIONID = Price.PRODUCTIONID AND
t.levelId = Price.levelId AND
Price.PRODUCTIONID = pro.PRODUCTIONID AND
Price.levelId = Price_level.levelId AND
t.bookingId = Booking.bookingId(+) AND
Booking.customerId = Customer.customerId(+) AND
ccons.cconcessionId(+) = t.cconcessionId AND
mcons.mconcessionId(+) = t.mconcessionId
(note old syntax)

Related

power query Expression.Error: We cannot convert a value of type Function to type List in power query

I am trying to run the query in power query editor and it failed with below error
where as the same query works fine in winserver 2016 and it fails with above error in win server 2019. Am I missing any thing ?
I did compared the settings and everything looks good.
let
//Get data Report H1
Source1 = Excel.Workbook(File.Contents("\\path\filename.xlsx"), null, true),
#"classic_Sheet1" = Source1{[Item = "classic", Kind = "Sheet"]}[Data],
#"Trimmed Text1" = Table.TransformColumns(#"classic_Sheet1", Text.Trim),
#"Third Row as Header1" = Table.PromoteHeaders(Table.Skip(#"Trimmed Text1", 2)),
#"Selected Columns1" = Table.SelectColumns(
#"Third Row as Header1",
{" ID", " Status", "Customer Id ", "Agent", "Leg"}
),
//Get Report H2
Source2 = Excel.Workbook(File.Contents("\\path\filename.xlsx"), null, true),
#"classic_Sheet2" = Source2{[Item = "classic", Kind = "Sheet"]}[Data],
#"Trimmed Text2" = Table.TransformColumns(#"classic_Sheet2", Text.Trim),
#"Third Row as Header2" = Table.PromoteHeaders(Table.Skip(#"Trimmed Text2", 2)),
#"Selected Columns2" = Table.SelectColumns(
#"Third Row as Header2",
{" ID", "Status", "Customer Id ", "Agent", "Leg"}
)
in
#"Excluded IDs"
The error message is pointing you to the problem:
Table.TransformColumns expects a list as the second parameter,
while you are providing a function:
Table.TransformColumns(
table as table,
transformOperations as list,
optional defaultTransformation as nullable function,
optional missingField as nullable number
) as table
Please read the official documentation here:
https://learn.microsoft.com/en-us/powerquery-m/table-transformcolumns
The issue has nothing to do with winserver 2016 or winserver 2019.
You want something along these lines
= Table.TransformColumns(#"classic_Sheet1",{{"ColumnNameHere", Text.Trim, type text}})
= Table.TransformColumns(#"classic_Sheet1"",{{"ColumnNameHere", Text.Trim, type text}, {"DifferentColumnNameHere", Text.Trim, type text}})

Unable to fetch the next_maintext of 2nd page

page1 and page2 URL. I want to fetch all the content from the 1st URL and only the main text from the 2nd URL and append it to the main text of 1st URL. This is only one article. function parse_indianexpress_archive_links() contains a list of news articles URLs. I m getting all the results from page1 but the next_maintext column from page2 results output <GET http://archive.indianexpress.com/news/congress-approves-2010-budget-plan/442712/2>
class spider_indianexpress(scrapy.Spider):
name = 'indianexpress'
start_urls = parse_indianexpress_archive_links()
def parse(self,response):
items = ScrapycrawlerItem()
separator = ''
#article_url = response.xpath("//link[#rel = 'canonical']/#href").extract_first()
article_url = response.request.url
date_updated = max(response.xpath("//div[#class = 'story-date']/text()").extract() , key=len)[-27:] #Call max(list, key=len) to return the longest string in list by comparing the lengths of all strings in a list
if len(date_updated) <=10:
date_updated = max(response.xpath("//div[#class = 'story-date']/p/text()").extract() , key=len)[-27:]
headline = response.xpath("(//div[#id = 'ie2013-content']/h1//text())").extract()
headline=separator.join(headline)
image_url = response.css("div.storybigpic.ssss img").xpath("#src").extract_first()
maintext = response.xpath("//div[#class = 'ie2013-contentstory']//p//text()").extract()
maintext = ' '.join(map(str, maintext))
maintext = maintext.replace('\r','')
contd = response.xpath("//div[#class = 'ie2013-contentstory']/p[#align = 'right']/text()").extract_first()
items['date_updated'] = date_updated
items['headline'] = headline
items['maintext'] = maintext
items['image_url'] = image_url
items['article_url'] = article_url
next_page_url = response.xpath("//a[#rel='canonical']/#href").extract_first()
if next_page_url :
items['next_maintext'] = scrapy.Request(next_page_url , callback = self.parse_page2)
yield items
def parse_page2(self, response):
next_maintext = response.xpath("//div[#class = 'ie2013-contentstory']//p//text()").extract()
next_maintext = ' '.join(map(str, next_maintext))
next_maintext = next_maintext.replace('\r','')
yield {next_maintext}
Output:
article_url,date_publish,date_updated,description,headline,image_url,maintext,next_maintext
http://archive.indianexpress.com/news/congress-approves-2010-budget-plan/442712/,,"Fri Apr 03 2009, 14:49 hrs ",,Congress approves 2010 budget plan,http://static.indianexpress.com/m-images/M_Id_69893_Obama.jpg,"The Democratic-controlled US Congress on Thursday approved budget blueprints embracing President Barack Obama's agenda but leaving many hard choices until later and a government deeply in the red. With no Republican support, the House of Representatives and Senate approved slightly different, less expensive versions of Obama's $3.55 trillion budget plan for fiscal 2010, which begins on October 1. The differences will be worked out over the next few weeks. Obama, who took office in January after eight years of the Republican Bush presidency, has said the Democrats' budget is critical to turning around the recession-hit US economy and paving the way for sweeping healthcare, climate change and education reforms he hopes to push through Congress this year. Obama, traveling in Europe, issued a statement praising the votes as ""an important step toward rebuilding our struggling economy."" Vice President Joe Biden, who serves as president of the Senate, presided over that chamber's vote. Democrats in both chambers voted down Republican alternatives that focused on slashing massive deficits with large cuts to domestic social spending but also offered hefty tax breaks for corporations and individuals. ""Democrats know that those policies are the wrong way to go,"" House Majority Leader Steny Hoyer told reporters. ""Our budget lays the groundwork for a sustained, shared and job-creating recovery."" But Republicans have argued the Democrats' budget would be a dangerous expansion of the federal government and could lead to unnecessary taxes that would only worsen the country's long-term fiscal situation. ""The Democrat plan to increase spending, to increase taxes, and increase the debt makes no difficult choices,"" said House Minority Leader John Boehner. ""It's a roadmap to disaster."" The budget measure is nonbinding but it sets guidelines for spending and tax bills Congress will consider later this year. BIPARTISANSHIP ABSENT AGAIN Obama has said he hoped to restore bipartisanship when he arrived in Washington but it was visibly absent on Thursday. ... contd.",<GET http://archive.indianexpress.com/news/congress-approves-2010-budget-plan/442712/2>
This is not how Scrapy works (I mean next_page request) How to fetch the Response object of a Request synchronously on Scrapy?.
But in fact you don't need synchronous requests. All you need is to check for a next page and pass current state (item) to the callback that will process your next page. I'm using cb_kwargs (it's a recommended way now). You may need to use request.meta if you have an old version.
import scrapy
class spider_indianexpress(scrapy.Spider):
name = 'indianexpress'
start_urls = ['http://archive.indianexpress.com/news/congress-approves-2010-budget-plan/442712/']
def parse(self,response):
item = {}
separator = ''
#article_url = response.xpath("//link[#rel = 'canonical']/#href").extract_first()
article_url = response.request.url
date_updated = max(response.xpath("//div[#class = 'story-date']/text()").extract() , key=len)[-27:] #Call max(list, key=len) to return the longest string in list by comparing the lengths of all strings in a list
if len(date_updated) <=10:
date_updated = max(response.xpath("//div[#class = 'story-date']/p/text()").extract() , key=len)[-27:]
headline = response.xpath("(//div[#id = 'ie2013-content']/h1//text())").extract()
headline=separator.join(headline)
image_url = response.css("div.storybigpic.ssss img").xpath("#src").extract_first()
maintext = response.xpath("//div[#class = 'ie2013-contentstory']//p//text()").extract()
maintext = ' '.join(map(str, maintext))
maintext = maintext.replace('\r','')
contd = response.xpath("//div[#class = 'ie2013-contentstory']/p[#align = 'right']/text()").extract_first()
item['date_updated'] = date_updated
item['headline'] = headline
item['maintext'] = maintext
item['image_url'] = image_url
item['article_url'] = article_url
next_page_url = response.xpath('//a[#rel="canonical"][#id="active"]/following-sibling::a[1]/#href').extract_first()
if next_page_url :
yield scrapy.Request(
url=next_page_url,
callback = self.parse_next_page,
cb_kwargs={
'item': item,
}
)
else:
yield item
def parse_next_page(self, response, item):
next_maintext = response.xpath("//div[#class = 'ie2013-contentstory']//p//text()").extract()
next_maintext = ' '.join(map(str, next_maintext))
next_maintext = next_maintext.replace('\r','')
item["maintext"] += next_maintext
next_page_url = response.xpath('//a[#rel="canonical"][#id="active"]/following-sibling::a[1]/#href').extract_first()
if next_page_url :
yield scrapy.Request(
url=next_page_url,
callback = self.parse_next_page,
cb_kwargs={
'item': item,
}
)
else:
yield item

How to assign variable in ‘Headers'

I have Report where the dates are as column headers.
The report is set as "show last x weeks" so each week the date should shift by 7 days, but it causes an issue down the line as PowerQuery fixes the header name as a constant into the code and does not update accordingly.
So this week report should start with 10/12/18 date range and end with 11/02/19.
= Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"Project
Location Name", "Role Name", "03/12/2018", "10/12/2018",
"17/12/2018", "24/12/2018", "31/12/2018", "07/01/2019", "14/01/2019",
"21/01/2019", "28/01/2019", "04/02/2019", "Total"}, {"Project Location
Name", "Role Name", "03/12/2018", "10/12/2018", "17/12/2018",
"24/12/2018", "31/12/2018", "07/01/2019", "14/01/2019", "21/01/2019",
"28/01/2019", "04/02/2019", "Total"})
One way to do this might be by changing this line:
Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"Project Location Name", "Role Name", "03/12/2018", "10/12/2018", "17/12/2018", "24/12/2018", "31/12/2018", "07/01/2019", "14/01/2019", "21/01/2019", "28/01/2019", "04/02/2019", "Total"}, {"Project Location Name", "Role Name", "03/12/2018", "10/12/2018", "17/12/2018", "24/12/2018", "31/12/2018", "07/01/2019", "14/01/2019", "21/01/2019", "28/01/2019", "04/02/2019", "Total"})
to:
let
headersToExpand = List.Distinct(List.Combine(List.Transform(#"Converted to Table"[Column1], Record.FieldNames))),
expandDynamically = Table.ExpandRecordColumn(#"Converted to Table", "Column1", headersToExpand)
in
expandDynamically
Assuming:
every row in "Column1" contains records,
your previous "step" is #"Converted to Table",
the column of records (that you want to expand) is called "Column1",
then the headersToExpand bit should give you a list of unique record field names (rather than the hard coded list you had) -- which can then be used in the expandDynamically step.

How to get the fields from a WorkItem using a WIQL in one call to speed up?

I've have the following code to get some specific WorkItems:
string workItemQueryString = "Select Id, State, Type From WorkItems Where [Work Item Type] = 'Code Review Request' And [Area Path] = 'abc' Order By [Changed Date] Desc";
var workItemQuery = new Query(workItemStore, workItemQueryString);
WorkItemCollection queryResults = workItemQuery.RunQuery();
This code runs fast (< 1 sec). However I also want to get some extra fields like "Associated Context Type" and "Associated Context".
So I use this code get get those fields:
var workItemDetails = queryResults.Cast<WorkItem>().Select(workItem => new WorkItemDetail
{
WorkItem = workItem,
AssociatedContextType = workItem.Fields.Contains("Associated Context Type") ? workItem.Fields["Associated Context Type"].Value : null,
AssociatedContext = workItem.Fields.Contains("Associated Context") ? workItem.Fields["Associated Context"].Value : null
}).ToList();
But this code runs very slow (13 to 20 seconds) which looks to me that separate queries (for each workitem?) are fired to the TFS server to get all data.
Note that when I use a Parallel.ForEach statement, the code breaks with an exception.
The total number of WorkItems in the WorkItemCollection is about 2800.
Try to change:
AssociatedContextType = workItem.Fields.Contains("AssociatedContextType") ? workItem.Fields["AssociatedContextType"].Value : null,
AssociatedContext = workItem.Fields.Contains("AssociatedContext") ? workItem.Fields["AssociatedContext"].Value : null
to:
AssociatedContextType = workItem.Fields.Contains("Associated Context Type") ? workItem.Fields["Associated Context Type"].Value : null,
AssociatedContext = workItem.Fields.Contains("Associated Context") ? workItem.Fields["Associated Context"].Value : null

LINQ Subquery issue

Following is my linq query:
var varResourceStatusReportDataBase =
(
from content in listContent
join workflowInstance in listWorkflkowInstance
on content.Field<string>("ows_ID").Trim()
equals workflowInstance.Field<string>("ows_Content ID").Split(';')[0].Trim()
join WorkflowInstanceStep in listWorkflowInstanceStep
on workflowInstance.Field<string>("ows_ID")
equals WorkflowInstanceStep.Field<string>("ows_Workflow Instance ID").Split(';')[0]
select new
{
ContentName = content.Field<string>("ows_Name"),
WorkflowInstanceId = workflowInstance.Field<string>("ows_ID"),
WIName = workflowInstance.Field<string>("ows_Title"),
WIPlannedStartDate = workflowInstance.Field<string>("ows_Planned Start Date") ?? "",
WIPlannedEndDate = workflowInstance.Field<string>("ows_Planned End Date") ?? "",
WIActualStartDate = workflowInstance.Field<string>("ows_Actual Start Date") ?? "",
WIActualEndDate = workflowInstance.Field<string>("ows_Actual End Date") ?? "",
WIApprovalDate = workflowInstance.Field<string>("ows_Approval Date") ?? "",
WITaskStatus = workflowInstance.Field<string>("ows_Status").ToUpper() ?? "",
WIMetadataStatus = workflowInstance.Field<string>("ows_Metadata Status") ?? "",
WIApprover = workflowInstance.Field<string>("ows_Approver").Replace("#", "").Split(';')[1].ToUpper() ?? "",
WISResponsible = WorkflowInstanceStep.Field<string>("ows_Responsible").Replace("#", "").Split(';')[1].ToUpper() ?? "",
WISDesiredEndDate=
(
from WorkflowInstanceStep1 in listWorkflowInstanceStep
where (WorkflowInstanceStep1.Field<string>("ows_Status") =="IN PROGRESS" ||
WorkflowInstanceStep1.Field<string>("ows_Status") =="ASSIGNED") &&
workflowInstance.Field<string>("ows_ID") == WorkflowInstanceStep1.Field<string>("ows_Workflow Instance ID").Split(';')[0]
select new {abc = WorkflowInstanceStep1.Field<string>("ows_Desired End Date")}).Take(1)
}).Distinct();
I have sub-query in above query to calculate WISDesiredEndDate, but when I execute this query, I get System.Linq.Enumerable+TakeIterator>d__3a'1[<>f__AnonymousType1'1[System.String]] value for WISDesiredEndDate column not actual value which I want.
Please give suggestion on the same.
Thanks.
You want FirstOrDefault() rather than Take(1)
As from comments, you don't want a anonymous object so change the select to be
select WorkflowInstanceStep1.Field<string>("ows_Desired End Date")}).FirstOrDefault()
You can us let clause more readable code. Nevertheless you have to force linq expression execution by calling FirstOrDefault method
let desiredEndDate = (from WorkflowInstanceStep1 in listWorkflowInstanceStep .... Take(1))
select new
{
...
WISDesiredEndDate= desiredEndDate.FirstOrDefault()
}

Resources