How do you align merged data in SQl - sql

I have three tables I want to combine into the Final Table in MSSQl2008. My problem lies in merging the data in the Final Table format. Another issue is the number of columns I have in each table close to 100 each so I need an efficient code that creates the final table
I need an SQl script that will generate the Final table
<h1> Table 2008</h1>
<table border = 1>
<tr>
<td> ID </Td>
<td> Sample_year </Td>
<td> Total_at_t-5 </Td>
<td> Total_at_t-4 </Td>
</tr>
<tr>
<td> MMM </Td>
<td> 2008 </Td>
<td> 5.25 </Td>
<td> 65.25</Td>
</tr>
</table>
<p> </p>
<h1> Table 2011</h1>
<table header = "2011" border = 1>
<tr>
<td> ID </Td>
<td> Sample_year </Td>
<td> Total_at_t-6 </Td>
<td> Total_at_t-5 </Td>
</tr>
<tr>
<td> MMM </Td>
<td> 2011 </Td>
<td> 7.25 </Td>
<td> 98.25</Td>
</tr>
</table>
<p> </p>
<h1> Table 2013</h1>
<table header = "2013" border = 1>
<tr>
<td> ID </Td>
<td> Sample_year </Td>
<td> Total_at_t-7 </Td>
<td> Total_at_t-6 </Td>
</tr>
<tr>
<td> MMM </Td>
<td> 2013 </Td>
<td> 3.25 </Td>
<td> 7.25</Td>
</tr>
</table>
<p> </p>
<h1> Table Final</h1>
<table hearder = "Final Table" border = 1>
<tr>
<td> ID </Td>
<td> Sample_year </Td>
<td> Total_at_t-7 </Td>
<td> Total_at_t-6 </Td>
<td> Total_at_t-5 </Td>
<td> Total_at_t-4 </Td>
</tr>
<tr>
<td> MMM </Td>
<td> NULL </Td>
<td> NULL </Td>
<td> NULL </Td>
<td> 5.25 </Td>
<td> 65025 </Td>
</tr>
<tr>
<td> MMM </Td>
<td> 2011 </Td>
<td> NULL </Td>
<td> 7.25</Td>
<td> 98.25 </Td>
<td> NULL </Td>
</tr>
<tr>
<td> MMM </Td>
<td> 2013 </Td>
<td> 3.25 </Td>
<td> 7.25 </Td>
<td> NUll </Td>
<td> NUll</Td>
</tr>
</table>

Just assume those Table exists in SQL database, if that the case, you only need to use Union (http://www.w3schools.com/sql/sql_union.asp) to join them together
declare #T2008 table (id varchar(3), sample_year int, [total_at_t-5] decimal(10, 2), [total_at_t-4] decimal(10, 2))
insert into #T2008 values ('MMM', 2008, 5.25, 65.25)
declare #T2011 table (id varchar(3), sample_year int, [total_at_t-6] decimal(10, 2), [total_at_t-5] decimal(10, 2))
insert into #T2011 values ('MMM', 2011, 7.25, 98.25)
declare #T2013 table (id varchar(3), sample_year int, [total_at_t-7] decimal(10, 2), [total_at_t-6] decimal(10, 2))
insert into #T2013 values ('MMM', 2013, 3.25, 7.25)
select id, sample_year, null as [total_at_t-7], null as [total_at_t-6], [total_at_t-5], [total_at_t-4]
from #T2008
union
select id, sample_year, null, [total_at_t-6], [total_at_t-5], null
from #T2011
union
select id, sample_year, [total_at_t-7], [total_at_t-6], null, null
from #T2013

Related

Sum referring another column

<table class="demo">
<caption>Sample Data</caption>
<thead>
<tr>
<th>Acct</th>
<th>Type</th>
<th>Amount</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<tr>
<td> 101</td>
<td> H</td>
<td> 0</td>
<td> 111</td>
</tr>
<tr>
<td> 102</td>
<td> H</td>
<td> 0</td>
<td> 106</td>
</tr>
<tr>
<td> 103</td>
<td> R</td>
<td> 10</td>
<td> 106</td>
</tr>
<tr>
<td> 104</td>
<td> R</td>
<td> 20</td>
<td> 106</td>
</tr>
<tr>
<td> 105</td>
<td> R</td>
<td> 30</td>
<td> 106</td>
</tr>
<tr>
<td> 106</td>
<td> T</td>
<td> 0</td>
<td> 111</td>
</tr>
<tr>
<td> 107</td>
<td> H</td>
<td> 0</td>
<td> 110</td>
</tr>
<tr>
<td> 108</td>
<td> R</td>
<td> 15</td>
<td> 110</td>
</tr>
<tr>
<td> 109</td>
<td> R</td>
<td> 25</td>
<td> 110</td>
</tr>
<tr>
<td> 110</td>
<td> T</td>
<td> 0</td>
<td> 111</td>
</tr>
<tr>
<td> 111</td>
<td> T</td>
<td> 0</td>
<td> </td>
</tr>
<tbody>
</table>
Suppose I have data as shown in this table. I want sum to be calculated in total accounts by referring Total Into column. Also, total accounts have their own higher-level linking where they should be summed up.
Can this be achieved in SQL server query? If not, then can someone guide me with SSRS expression to achieve this?
I tried to achieve this with multiple nested queries, partition by clause, etc. Then I switched to SSRS and tried a few expressions. But now I'm kind of stuck

Which could be the best Xpath to Get text when there is a text on both <td>

I have the follow xml which I need to scrape:
<div class="tab_product_details">
<table>
<tbody>
<tr>...</tr>
<tr>...</tr>
<tr>...</tr>
<tr>
<td> text 1 </tr>
<td> text 2 </tr>
</tr>
<tr>
<td colspan = "2">
<table>
<tbody>
<tr>
<td> Adjustment</td> this text i do not need it!
<td></td>
</tr>
<tr class="feature">
<td> text3</td>
<td> text4 </td>
</tr>
My actual xpath is the following:
text1 =response.xpath('//div[contains(#class,"tab_product_details")]//td[followingsibling::td[not(table)]]')
text2 = response.xpath('//div[contains(#class,"tab_product_details")]//td[2]')
But I continue to get the texts that have no pair
Any help very welcome, thanks!
If you want to get text if both cells (td) are not empty try
//div[#class = "tab_product_details"]//tr[count(./td[normalize-space()]) = 2]/td/text()[1]
//div[#class = "tab_product_details"]//tr[count(./td[normalize-space()]) = 2]/td/text()[2]

xpath method of Selenium does not work for Google chrome

I don't have a lot of experience with Selenium but I am trying to run a code which search for an element in HTML with chromedriver. I keep getting an error as below. The first thing I would like to confirm is that this error cannot be due to the connection with Chromedriver to the web but is because of the way the python script search in the HTML code. Any help would be appreciated.
The error:
('no such element: Unable to locate element: {"method":"xpath","selector":"//*[contains(text(),\'Find exited companies announced\')]/../.."}\n (Session info: headless chrome=91.0.4472.101)', None, None)
The code source:
<div id="logon-brownContent" style="width:100%;display:true;;padding-bottom: 0px;" class="hideforprinting">
<table width="" cellpadding="0" cellspacing="0" class="">
</table>
</div>
</div>
</td></tr></table>
</div>
</td>
<td class="homepage_mainbody-headlines">
<table class="framework_standard">
<tr>
<td colspan="2" valign="top">
<form action="exitbroker.asp?" method="post" name="oz" id="oz" sumbit="javascript:return validate();">
<input type="hidden" name="verb" value="8" />
<input type="hidden" name="dateformat" value="dd/mm/yyyy" />
<input type="hidden" name="contextid" value="1032390856" />
<input type="hidden" name="statecodelength" value="0" />
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td>
<table>
<tr>
<td class="framework_page-title">
<span class="framework_page-title">PE Exit Companies: Search</span><br/>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="1"><img src="/images/spacer.gif" height="13" width="1"></td>
</tr>
</table>
<table class="criteriaborder" cellspacing="0" cellpadding="2" width="100%" border="0">
<tbody>
<tr>
<td>
<table cellspacing="0" cellpadding="0" border="0" style="width:100%;">
<tbody>
<tr>
<td valign="top">
<table cellspacing="0" cellpadding="0" width="100%" border="0">
<tr>
<td align="center" valign="middle" width="100%" height="18" class="criteriaheader2">Exits</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="criteriasectionheader"><br />Exit Types</td>
</tr>
<tr>
<td>
<table border="0" cellpadding="0" cellspacing="0">
<tr valign="top"><td width="200"><input type="checkbox" name="exitdealtype" value="ipo"/>Initial Public Offering</td><td width="200"><input type="checkbox" name="exitdealtype" value="sbo"/>Secondary Buyout</td><td width="200"><input type="checkbox" name="exitdealtype" value="tradesale"/>Trade Sale</td></tr>
</table>
</td>
</tr>
<tr>
<td class="criteriasectionheader"><br />Date Range</td>
</tr>
<tr>
<td>
Find exited companies announced<br><br>
</td>
</tr>
<tr>
<td>
<table cellpadding="2" cellspacing="0" border="0">
<tr>
<td>From </td>
<td><input type="text" name="datefrom" style="width:100" value=""></td>
<td> To </td>
<td><input type="text" name="dateto" style="width:100" value=""></td>
<td> Clear Date</td>
</tr>
<tr>
<td> </td>
<td><span class="hint">(dd/mm/yyyy)</span></td>
<td> </td>
<td><span class="hint">(dd/mm/yyyy)</span></td>
<td> </td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<br />
Please Note: The default start date for our searches has been changed to 01/01/2005. You can still access all
<br />
of our historical data by inserting the desired start date above. For help or further information please contact
<br />
your Customer Relationship Consultant.
<br />
</td>
</tr>
<tr>
<td class="criteriasectionheader"><br />Industry</td>
</tr>
<tr>
<td>
Find exited companies in these sectors.
<br />The industries defined here are affiliated with both the core business and divisions of the portfolio/exited companies.
<br />Multiple select using ctrl and click. The default is set to all.<br><br>
</td>
</tr>
<tr>
<td>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td><span class="criterialabel">Sectors<img src="/includes/images/mm-info-icon.gif"></span></td>
<td><span class="criterialabel">Sub-Sectors</span></td>
</tr>
<tr>
<td><select multiple="multiple" size="6" name="sectorcode" style="width:250px" onChange="javascript:emptyListBox(document.oz.subsectorcode);fillSelect(document.oz.subsectorcode,null,buildSelectedItems(document.oz.sectorcode));"></select> </td>
<td><select multiple="multiple" size="6" name="subsectorcode" style="width:250px"></select> </td>
</tr>
<tr>
<td><a name="selectAllSubsectorLink" href="javascript:fillSelect(document.oz.subsectorcode,null,buildSelectedItems(document.oz.sectorcode));selectAll(document.oz.sectorcode);fillSelect(document.oz.subsectorcode,null,buildSelectedItems(document.oz.sectorcode));">Select All Sectors</a> </td>
<td>Select All Sub-Sectors </td>
</tr>
<tr>
<td>Clear All<br><br></td>
</tr>
<tr>
<td colspan="4">
<input type="hidden" name="normalsectorsearch" value="" />
<input type="hidden" name="normalsubsectorsearch" value="" />
<input type="checkbox" name="domsectoronly" value="true" onclick="javascript:deselectAll(document.oz.subsectorcode);setItemDisableStatus(document.oz.subsectorcode);setItemDisableStatus(document.oz.selectAllSubsectorLink);">Search by dominant sector only<a href="javascript:displayPEPortfolioDominantSectorCountryGlossary('../includes/glossary');"><img src="/includes/images/mm-info-icon.gif" title="More information" />
</td>
</tr>
</table>
</td>
<!--
<td><select size="6" multiple="multiple" name="sectorcode" style="width:250px" ></select> </td>
</tr>
<tr>
<td>
Select All
Clear All
</td>
</tr>
-->
</tr>
<tr>
<td style="TEXT-ALIGN: right;" class="search_buttons_right">
<input type="button" value="Save Search" class="framework_flatbutton" onclick="javascript:if (validatePage(document.oz)) {document.oz.verb.value=1;document.oz.target='_self';document.oz.submit();};"/>
<!-- a onmouseover="style.cursor = 'hand'" onclick="javascript:if (validatePage(document.oz)) {document.oz.verb.value=28;defaultDatesWithLocale( document.oz.datefrom, document.oz.dateto, 'dd/mm/yyyy' );if (verifyDateSubSectors(document.oz.datefrom.value)) {countWindow();document.oz.target='_self';document.oz.submit();}}"><img src="/images/button_countresults.gif" border="0" /></a -->
<input type="button" value="Count Results" class="framework_flatbutton" onclick="javascript:submitCount();" />
<!-- a onmouseover="style.cursor = 'hand'" onclick="javascript:if (validatePage(document.oz)) {document.oz.verb.value=8;defaultDatesWithLocale( document.oz.datefrom,document.oz.dateto, 'dd/mm/yyyy' );document.oz.target='_self';if (verifyDateSubSectors(document.oz.datefrom.value)) {document.oz.target='_self';document.oz.submit();}};"><img src="/images/button_search.gif" border="0" /></a -->
<input type="button" value="Search" class="framework_flatbutton" onclick="javascript:if (validatePage(document.oz)) {
document.oz.verb.value=8
;document.oz.target='_self'
defaultDatesWithLocale( document.oz.datefrom,document.oz.dateto, 'dd/mm/yyyy' );
; document.oz.target='_self';
document.oz.submit();
}" />
</td>
</tr>
</tbody>
</table>
</tr>
</td>
</tbody>
</table>
<table>
<tr>
<td>
<br>
</td>
</tr>
</table>
<table class="criteriaborder" cellspacing="0" cellpadding="2" width="100%" border="0">
<tbody>
<tr>
<td>
<table cellspacing="0" cellpadding="0" border="0" style="width:100%;">
<tbody>
<tr>
<td valign="top">
<table cellspacing="0" cellpadding="0" width="100%" border="0">
<tr>
<td align="center" valign="middle" width="100%" height="18" class="criteriaheader2">Further Search Criteria</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="criteriasectionheader"><br/>Geography</td>
</tr>
<tr>
<td>Find exited companies in these locations.
<br />Multiple select using ctrl and click. The default is set to all. </td>
</tr>
<tr>
<td>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
<td> </td>
<td> </td>
<td><img src="/images/spacer.gif" width="10" height="1" alt="" /></td><td> </td>
</tr>
<tr>
<td><select multiple="multiple" size="6" name="areacode" style="width:200px" onChange="javascript:emptyListBox(document.oz.regioncode);emptyListBox(document.oz.countrycode);fillSelect(document.oz.regioncode,null,buildSelectedItems(document.oz.areacode));emptyListBox(document.oz.statecode);"></select></td>
<td><select multiple="multiple" size="6" name="regioncode" style="width:200px" onChange="javascript:emptyListBox(document.oz.countrycode);fillSelect(document.oz.countrycode,null,buildSelectedItems(document.oz.regioncode));emptyListBox(document.oz.statecode);"></select></td>
<td><select multiple="multiple" size="6" name="countrycode" style="width:200px" onChange="javascript:emptyListBox(document.oz.statecode);fillSelect(document.oz.statecode,null,buildSelectedItems(document.oz.countrycode));"></select></td>
<td> </td><td><select multiple="multiple" size="6" name="statecode" style="width:200px"></select></td>
</tr>
<tr>
<td>Select All</td>
<td>Select All</td>
<td>Select All</td>
<td> </td><td>Select All</td>
</tr>
<tr>
<td>Clear All</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="criteriasectionheader"><br/>PE House</td>
</tr>
<tr>
<td>Find exit companies who are currently held by specific PE Houses.
<br />Maximum of 50 selections allowed.</td >
</tr>
<tr>
<td>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<a class="search_lookup" href="javascript:openWin('qpehousenotapproved','hyperlink','pehousesysid','select-multiple','pehousesysiddescription','');">Lookup</a>
</td>
</tr>
<tr>
<td>
<select size="4" multiple="multiple" name="pehousesysid" style="width:350px"></select>
<input type="hidden" name="pehousesysiddescription" />
</td>
</tr>
<tr>
<td>
Remove
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="criteriasectionheader"><br/>Advisors</td>
</tr>
<tr>
<td>
Find exited companies who have been advised by these companies.
<br />Maximum of 50 selections allowed.
</td>
</tr>
<tr>
<td>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<a class="search_lookup" href="javascript:openWin('ecadvisor','hyperlink','advisorcompanysysid','select-multiple','advisorcompanysysiddescription','');">Lookup</a>
</td>
</tr>
<tr>
<td>
<select size="4" multiple="multiple" name="advisorcompanysysid" style="width:350px"></select>
<input type="hidden" name="advisorcompanysysiddescription" />
</td>
</tr>
<tr>
<td>
Remove
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td><br /><span class="criteriasectionheader">Deal Value</span></td>
</tr>
<tr>
<td>Find exited companies with the following deal value. </td>
</tr>
<tr>
<td>
<table>
<tr>
<td><p><span class="criterialabel">Currency</span></p></td>
<td> </td>
<td><select id="currencycode" name="currencycode"><option value="AUD">AUD</option>
<option value="CHF">CHF</option>
<option value="CNY">CNY</option>
<option value="EUR">EUR</option>
<option value="GBP">GBP</option>
<option value="HKD">HKD</option>
<option value="INR">INR</option>
<option value="JPY">JPY</option>
<option value="USD" selected="">USD</option></select></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table>
<tr>
<td width="180"><p><span class="criterialabel">Minimum value in millions</span></p></td>
<td> </td>
<td><p><input type="text" name="mindealvalue" size="12" value="" onkeypress="checkMinimumValue();" onkeyup="checkMinimumValue();" /></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table>
<tr>
<td width="180"><span class="criterialabel">Maximum value in millions</span></td>
<td> </td>
<td><input type="text" name="maxdealvalue" size="12" value=""></td>
</tr>
</table>
</td>
</tr>
<tr><td><br>Include deals with undisclosed value <input type="checkbox" name="undiscloseddealvalues" value="true" Checked></td></tr>
<tr>
<td class="criteriasectionheader"><br/>Exited Companies</td>
</tr>
<tr>
<td>Maximum of 50 selections allowed.</td >
</tr>
<tr>
<td>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<a class="search_lookup" href="javascript:openWin('eccompany','hyperlink','eccompanysysid','select-multiple','eccompanysysiddescription','');">Lookup</a>
</td>
</tr>
<tr>
<td>
<select size="4" multiple="multiple" name="eccompanysysid" style="width:350px"></select>
<input type="hidden" name="eccompanysysiddescription" />
</td>
</tr>
<tr>
<td>
Remove
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="criteriasectionheader"><br/>Free Text Search</td>
</tr>
<tr>
<td>Please use the Free Text Search by typing in a keyword or phrase to identify the required portfolio.
<br />
<span class="hint">Searches on companies' information, deal description, and condition, type, nature, consideration structure.<br><br></span>
</td>
</tr>
<tr>
<td>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="150" class="criterialabel">Search</td>
<td><input type="text" name="textsearch" style="width:250px" value="" /></td>
<td><table border="0" cellpadding="0" cellspacing="0">
<tr valign="top"><td width="350"><input checked type="radio" name="andorfreetext" value="and"/>Match all words<br><input type="radio" name="andorfreetext" value="or"/>Match any word<br><input type="radio" name="andorfreetext" value="phrase"/>Match exact phrase</td></tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td style="TEXT-ALIGN: right;" class="search_buttons_right">
<input type="button" value="Save Search" class="framework_flatbutton" onclick="javascript:if (validatePage(document.oz)) {document.oz.verb.value=1;document.oz.target='_self';document.oz.submit();};"/>
<!-- a onmouseover="style.cursor = 'hand'" onclick="javascript:if (validatePage(document.oz)) {document.oz.verb.value=28;defaultDatesWithLocale( document.oz.datefrom, document.oz.dateto, 'dd/mm/yyyy' );if (verifyDateSubSectors(document.oz.datefrom.value)) {countWindow();document.oz.target='_self';document.oz.submit();}}"><img src="/images/button_countresults.gif" border="0" /></a -->
<input type="button" value="Count Results" class="framework_flatbutton" onclick="javascript:submitCount();" />
<!-- a onmouseover="style.cursor = 'hand'" onclick="javascript:if (validatePage(document.oz)) {document.oz.verb.value=8;defaultDatesWithLocale( document.oz.datefrom,document.oz.dateto, 'dd/mm/yyyy' );document.oz.target='_self';if (verifyDateSubSectors(document.oz.datefrom.value)) {document.oz.target='_self';document.oz.submit();}};"><img src="/images/button_search.gif" border="0" /></a -->
<input type="button" value="Search" class="framework_flatbutton" onclick="javascript:if (validatePage(document.oz)) {
document.oz.verb.value=8
;document.oz.target='_self';
defaultDatesWithLocale( document.oz.datefrom,document.oz.dateto, 'dd/mm/yyyy' );
document.oz.target='_self';
document.oz.submit();
}" />
</td>
</tr>
</tbody>
</table>
</tr>
</td>
</tbody>
</table>
</form>
<script LANGUAGE="JavaScript">
<!--
function validatePage(objitem) {
selectAll(objitem.pehousesysid);
selectAll(objitem.eccompanysysid);
objitem.eccompanysysid.required=false;
objitem.eccompanysysid.description='Portfolio Company Name';
objitem.eccompanysysid.datatype='alphanumeric';
selectAll(objitem.advisorcompanysysid);
objitem.advisorcompanysysid.required=false;
objitem.advisorcompanysysid.description='Advisor Name';
objitem.advisorcompanysysid.datatype='alphanumeric';
// locale info.
objitem.localedateformat='dd/mm/yyyy';
objitem.localecurrencycode='USD';
objitem.localelanguagecode='en_eu';
objitem.localetimezone='235';
objitem.mindealvalue.required=false;
objitem.mindealvalue.description='Currency minimum value in millions';
objitem.mindealvalue.datatype='decimal';
objitem.mindealvalue.min =0;
objitem.mindealvalue.max=1000000000000000000;
objitem.maxdealvalue.required=false;
objitem.maxdealvalue.description='Currency maximum value in millions';
objitem.maxdealvalue.datatype='decimal';
objitem.maxdealvalue.min=0;
objitem.maxdealvalue.max=1000000000000000000;
objitem.datefrom.required=false;
objitem.datefrom.description='Date from';
objitem.datefrom.datatype='date';
objitem.dateto.required=false;
objitem.dateto.description='Date to';
objitem.dateto.datatype='date';
if (objitem.statecode)
{
objitem.statecodelength.value = objitem.statecode.length;
}
// DanielC: 7/11/08: Case 107136: set the hidden field so that it will end up in the token XML and can be used in criteria.xml
if (document.oz.domsectoronly.checked == false)
{
document.oz.normalsectorsearch.value = "true";
document.oz.normalsubsectorsearch.value = "true";
}
return verify(objitem,false);
}
function submitCount()
{
if (validatePage(document.oz)) {
var dOz = document.oz;
//need to change pPopup variable to pPopup=1 to ensure no chrome on popup in event of failure
var vAction = dOz.action;
dOz.action = (dOz.action.search(/pPopup/) == -1) ? dOz.action+= "&pPopup=1" : dOz.action.replace(/pPopup=./,"pPopup=1");
defaultDatesWithLocale( document.oz.datefrom,document.oz.dateto, 'dd/mm/yyyy' );
dOz.verb.value=28;
countWindow();
document.oz.submit();
dOz.action = vAction;
}
}
//-->
</script>
</td>
</tr>
</table>
</td>
<td class="homepage_mainbody-leaguetbl"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="100%"><img src="/images/spacer.gif" width="1" height="1"></td>
</tr>
</table>
</td>
</tr>
</table>
</div><footer class="acuris-footer" xmlns:msxsl="urn:schemas
A piece of code with xpath not sending error:
def openSearchPageCommon(self,url,clear_xpath) :
self.drv.get(url)
for x in self.drv.find_elements_by_xpath(clear_xpath) :
x.click()
def openSearchPage(self) :
xpath = "//form[#action='portfoliobroker.asp?']//table//*[contains(text(),'Clear Date')]"
self.openSearchPageCommon(self.tgt,xpath)
Full error:
Traceback (most recent call last):
File "mmmm_lib.py", line 73, in __init__
self.drv.find_element_by_xpath("//*[contains(text(),'Find exited companies announced')]/../..")
File "/home/airflow/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 394, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "/home/airflow/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 978, in find_element
'value': value})['value']
File "/home/airflow/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/airflow/.local/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[contains(text(),'Find exited companies announced')]/../.."}
May be its because the element you are trying to locate is in an iframe or in a shadow dom. And also make sure that the xpath points only one element in the Dom.
If its in an iframe you need switch to that frame and then try to locate the element.
if its in a shadow root, open you need to get the shadow-root first to locate the required element.
I think we should try with css selector written below :-
table.criteriaborder:nth-of-type(2) tr:nth-of-type(5) td
since the xpath that you are using, depends on a text which is basically a text node
if it's python that you are working on, you could try the below code :
print(driver.find_element_by_css_selector("table.criteriaborder:nth-of-type(2) tr:nth-of-type(5) td").text)

Simple. How to right aligned a table?? What Am I missing?

I have search extensively and have not had any luck. I have try some of the right aligned coding and I appear to just make things worse. I try to research and fix the problem without asking question but here I am. Basically I need my table to right aligned. The table that has "invoice, date, total, payments, and balance remaining". I have attached a photo also. The code I have for just the table is below:
<div class="col-xs-4">
<table class="table">
<tbody>
<tr>
<td>
<strong>Invoice</strong>
</td>
<td class="text-right">
{{ job.job_number }}
</td>
</tr>
<tr>
<td>
<strong>Date</strong>
</td>
<td class="text-right">
{% if job.scheduled_on %}
{{ job.scheduled_on | date: "%m/%d/%y" }}
{% endif %}
</td>
</tr>
<tr>
<td>
<strong>Total</strong>
</td>
<td class="text-right">
{{ job.total | currency }}
</td>
</tr>
<tr>
<td>
<strong>Payments</strong>
</td>
<td class="text-right">
{{ job.total_applied_payments | currency }}
</td>
</tr>
<tr>
<td>
<strong>Balance Remaining</strong>
</td>
<td class="text-right">
{{ job.balance | currency }}
</td>
</tr>
</tbody>
</table>
</div><!-- .col-xs-4 -->
</div><!-- .row -->
photo

Join 2 rows into one based on condition

I´m fairly new to SQL and can´t get this around my head and need some help!
My table look something like this:
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="307" colspan="3" valign="top">
<p>
<strong>Kompetens</strong>
</p>
</td>
</tr>
<tr>
<td width="102" valign="top">
<p>
<strong>Emp.nr</strong>
</p>
</td>
<td width="102" valign="top">
<p>
<strong>Code</strong>
</p>
</td>
<td width="102" valign="top">
<p>
<strong>EndDate</strong>
</p>
</td>
</tr>
<tr>
<td width="102" valign="top">
<p>
111
</p>
</td>
<td width="102" valign="top">
<p>
Dansa1
</p>
</td>
<td width="102" valign="top">
<p>
2015-01-01
</p>
</td>
</tr>
<tr>
<td width="102" valign="top">
<p>
111
</p>
</td>
<td width="102" valign="top">
<p>
Dansa2
</p>
</td>
<td width="102" valign="top">
<p>
2015-02-01
</p>
</td>
</tr>
<tr>
<td width="102" valign="top">
<p>
222
</p>
</td>
<td width="102" valign="top">
<p>
Dansa1
</p>
</td>
<td width="102" valign="top">
<p>
2015-01-01
</p>
</td>
</tr>
<tr>
<td width="102" valign="top">
<p>
222
</p>
</td>
<td width="102" valign="top">
<p>
Dansa2
</p>
</td>
<td width="102" valign="top">
</td>
</tr>
<tr>
<td width="102" valign="top">
<p>
333
</p>
</td>
<td width="102" valign="top">
<p>
Dansa1
</p>
</td>
<td width="102" valign="top">
</td>
</tr>
<tr>
<td width="102" valign="top">
<p>
333
</p>
</td>
<td width="102" valign="top">
<p>
Dansa2
</p>
</td>
<td width="102" valign="top">
<p>
2015-02-02
</p>
</td>
</tr>
<tr>
<td width="102" valign="top">
<p>
444
</p>
</td>
<td width="102" valign="top">
<p>
Dansa1
</p>
</td>
<td width="102" valign="top">
<p>
2015-01-01
</p>
</td>
</tr>
<tr>
<td width="102" valign="top">
<p>
444
</p>
</td>
<td width="102" valign="top">
<p>
Dansa2
</p>
</td>
<td width="102" valign="top">
<p>
2015-02-01
</p>
</td>
</tr>
</tbody>
</table>
I would like to merge into 1 row per employee where both Dansa1 and Dansa2 has a EndDate. Like this:
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="102" valign="top">
<p>
<strong>Emp.nr</strong>
</p>
</td>
<td width="102" valign="top">
<p>
<strong>EndDate</strong>
</p>
</td>
</tr>
<tr>
<td width="102" valign="top">
<p>
111
</p>
</td>
<td width="102" valign="top">
<p>
2015-02-01
</p>
</td>
</tr>
<tr>
<td width="102" valign="top">
<p>
444
</p>
</td>
<td width="102" valign="top">
<p>
2015-02-01
</p>
</td>
</tr>
</tbody>
</table>
I also use a string variable to select wich employees to include:
SELECT [Emp.nr], [Code]
FROM [Kompetens]
WHERE [Emp.nr] IN #strEmp.nr
You wish to show only rows that have both entries, dansa1 and dansa2.
You can do so with group by, count and having:
SELECT [Emp.nr], max([EndDate])
FROM [Kompetens]
GROUP BY [Emp.nr]
HAVING count(*) > 1
Note: Like this, you don't precisely check if both rows have "Dansa1" and "Dansa2". It would also work if they had "Dansa1" twice. with max(), you select only the latest date.
Edit:
If you have rows that e.g. have no value in the field Code, then you can exclude them with the where clause, like this:
SELECT [Emp.nr], max([EndDate])
FROM [Kompetens]
WHERE Code IS NOT NULL AND Code != ""
GROUP BY [Emp.nr]
HAVING count(*) > 1
Where narrows the basis the aggregate functions are working with. Having narrows the result set created by the aggregate functions.
You can use group by . The query will look like :
SELECT [Emp.nr], [EndDate]
FROM [Kompetens]
group by [Emp.nr], [EndDate]