how to handle error Subquery returned more than 1 value this example? - sql

how to handle error Subquery returned more than 1 value this example?
declare #html xml = N'<div itemtype="http://schema.org/Product"><table width="100%" cellspacing="0" cellpadding="2"><tr><td><table><tr><td class="navigation" >Battery Adapter > Laptop CPU Fan > ASUS >A8 Series </td><td></td></tr></table></td></tr><tr><td><table align="center" class="product-more" width="99%"><tr><td colspan="5" class="pageHeading" align="left">Please select your right product for A8 Series from the list below.</td></tr><tr><td width="117"><img src="images/sma/FASF3.jpg" alt="Original Brand New ASUS F3, F8 Series CPU Cooling Fan -- GC054509VH-A 3-PinS" title=" Original Brand New ASUS F3, F8 Series CPU Cooling Fan -- GC054509VH-A 3-PinS " width="100" height="75" hspace="5" vspace="5"/> </td><td width="226">Original Brand New ASUS F3, F8 Series CPU Cooling Fan -- GC054509VH-A 3-PinS</td><td width="13"></td><td width="116" class="price_product">$10.96</td><td width="113"><font color="blue"><b/>In Stock</font></td></tr><tr><td width="117"><img src="images/sma/FASF3J.jpg" alt="Original Brand New ASUS F3, F3J, A8 Series CPU Cooling Fan -- GC055515VH-A 4-PinS" title=" Original Brand New ASUS F3, F3J, A8 Series CPU Cooling Fan -- GC055515VH-A 4-PinS " width="100" height="75" hspace="5" vspace="5"/> </td><td width="226">Original Brand New ASUS F3, F3J, A8 Series CPU Cooling Fan -- GC055515VH-A 4-PinS</td><td width="13"></td><td width="116" class="price_product">$10.96</td><td width="113"><font color="blue"><b/>In Stock</font></td></tr></table></td></tr><tr><td style="font:bold 11px Verdana, Arial, Helvetica, sans-serif; color:#3D9D17;">This product has <font color="#0000FF">2 </font>types </td></tr><tr><td>&nbsp;</td></tr><tr><td><table width="98%" cellspacing="0" cellpadding="0"><tr><td class="pageHeading" height="30" align="center"><h1><b/><span itemprop="name"><a name="product0"></a>Original Brand New ASUS F3, F8 Series CPU Cooling Fan -- GC054509VH-A 3-PinS </span></h1></td></tr><tr><td class="welcome_index"><span itemprop="description"> Get your ASUS A8 Series Laptop Fan from battery-adapter.com today is free of charge for shipment. We supply high quality ASUS A8 Series Laptop CPU Fan with low price. We guarantee the ASUS A8 Series Laptop CPU Cooling Fan with a full three-months warranty from the date of purchase if the product(s) have any quality problem!</span></td></tr></table></td></tr><tr><td><div itemprop="offers" itemtype="http://schema.org/Offer"><table width="100%" cellspacing="0" cellpadding="0"><tr><td valign="top" class="main" width="31%" align="right"><table width="100%" cellpadding="2" cellspacing="1"><tr><td style="border-right:1px dashed; border-bottom:1px dashed;" width="48%" height="2" align="center"><table cellspacing="0" cellpadding="2"><tr><td align="center" class="smallText"></td></tr><tr><td align="center" class="smallText"><img src="images/mid/FASF3.jpg" alt="Original Brand New ASUS F3, F8 Series CPU Cooling Fan -- GC054509VH-A 3-PinS" title=" Original Brand New ASUS F3, F8 Series CPU Cooling Fan -- GC054509VH-A 3-PinS "/>Click image to enlarge<noscript><img src="images/mid/FASF3.jpg" alt="Original Brand New ASUS F3, F8 Series CPU Cooling Fan -- GC054509VH-A 3-PinS" title=" Original Brand New ASUS F3, F8 Series CPU Cooling Fan -- GC054509VH-A 3-PinS "/>Click image to enlarge </noscript></td></tr><tr><td align="center" class="price_product"><meta itemprop="priceCurrency" content="USD" /><span itemprop="price" content="10.96">$10.96</span></td></tr><tr><td align="center" style="font:bold 14px Verdana, Arial, Helvetica, sans-serif; color:#3D9D17;">Free Shipping</td></tr><tr><td align="center" style="font:bold 14px Verdana, Arial, Helvetica, sans-serif; color:#3D9D17;">Brand new,3 months warranty!</td></tr><tr><td align="center"></td></tr><tr><td align="center"><img src="images/ce.gif" alt="Authentication"/></td></tr></table></td><td valign="top" style="border-bottom:1px dashed;"><table width="100%" cellpadding="2" cellspacing="0"><tr><td valign="bottom" align="left" style=" font:bold 11px Verdana, Arial, Helvetica, sans-serif;color:#3B4F89; border-bottom:double #3B4F89;">ASUS A8 Series Laptop Accessory Information: </td></tr><tr><td class="main"><b/>Specification: Brand New ASUS F3, F8 Series CPU Cooling FANTested to be 100% working properly. <b/>Unit: PCS <b/>Type: Laptop CPU Fan<meta itemprop="itemCondition" itemtype="http://schema.org/OfferItemCondition" content="http://schema.org/NewCondition"/><b/>Condition: Brand New<b/>Warranty: 3 Months<b/>Power: 5V 0.38A<b/>Info: Size (mm): 57 x 57 x 10, Wire Length: 75mm, (3 wire)3-pin connector</td></tr> <tr><td class="main"><b/>Availability:&nbsp;<meta itemprop="availability" content="http://schema.org/InStock"/>In Stock</td></tr><tr><td class="main"><b/>Payment | Delivery:&nbsp;PayPal | HongKong Registered Air Mail With Tracking Number, Free&nbsp;&nbsp;<a class="resources-newproduct" href="product_info.php/products_id/3851/3921/vA8+Series#bottom" title="Jump to detail of payment and shipping">[Detail?]</a></td></tr><tr><td height="30" align="left" valign="middle"><img src="includes/languages/english/images/buttons/button_in_cart.gif" alt="Add to Cart" title=" Add to Cart " width="93" height="24"/> </td></tr><tr><td><!-- tell_a_friend //--><table width="100%" cellspacing="0" cellpadding="1" class="infoBox"><tr><td><table width="100%" cellspacing="0" cellpadding="0" class="infoBoxContents"><tr><td><img src="images/pixel_trans.gif" alt="" width="100%" height="1"/></td></tr><tr><td align="left" class="boxText"><form name="tell_a_friend" action="https://www.battery-adapter.com/tell_a_friend.php" method="get"><a class="index_newlink" href="https://www.battery-adapter.com/product_reviews.php/products_id/3851"><img class="image_float" alt="View & Write Reviews" src="includes/languages/english/images/buttons/button_write_view.gif" /></a><a class="index_newlink" href="https://www.battery-adapter.com/ask_question.php/products_id/3851"><img class="image_float" alt="Ask a question" src="includes/languages/english/images/buttons/button_ask_question.gif" /></a></form></td></tr><tr><td><img src="images/pixel_trans.gif" alt="" width="100%" height="1"/></td></tr></table></td></tr></table><!-- tell_a_friend_eof //--></td></tr></table></td></tr></table></td></tr></table></div></td></tr><tr><td>&nbsp;</td></tr><tr><td> <div id="modelinfo0"><table width="99%" align="center" cellpadding="2" cellspacing="1" bgcolor="#F2E9D5"><tr><td colspan="2" class="replacement" height="25">&nbsp;<h2><b/>Compatible ASUS A8 Series Part Number and Models:</h2></td><td align="center"><a class="footerproduct" href="product_info.php/products_id/3851/3921/vA8+Series#brands0">Compatible Brands</a></td></tr><tr bgcolor="#FFFFFF"><td colspan="3" class="product_partno">Compatible Code</td></tr><tr bgcolor="#FFFFFF"><td width="34%" class="pro_in">13.V1.B3564.F.GN</td><td width="33%" class="pro_in">GC054509VH-A</td><td width="33%"></td></tr><tr bgcolor="#FFFFFF"><td colspan="3" class="product_partno">Fit Model</td></tr><tr bgcolor="#FFFFFF"><td width="34%" class="pro_in">A8 Series</td><td width="33%" class="pro_in">F3 Series</td><td width="33%" class="pro_in">F3T Series</td></tr><tr bgcolor="#FFFFFF"><td width="34%" class="pro_in">F8 Series</td><td width="33%" class="pro_in">F8S Series</td><td width="33%" class="pro_in">F8SR Series</td></tr><tr bgcolor="#FFFFFF"><td width="34%" class="pro_in">F8SV Series</td><td width="33%" class="pro_in">F8Sa Series</td><td width="33%" class="pro_in">F8VA Series</td></tr><tr bgcolor="#FFFFFF"><td width="34%" class="pro_in">Z91V Series</td><td width="33%" class="pro_in">Z99J Series</td><td width="33%"></td></tr></table></div></td></tr><tr><td><table width="99%" align="center" cellpadding="2" cellspacing="1" bgcolor="#F2E9D5"><tr><td colspan="3" class="replacement" height="25"><a name="brands0" title="Compatible brands"></a><h2><b/>Compatible Brands (Select brand to view models)</h2></td></tr><tr bgcolor="#FFFFFF"><td class="pro_in"><a class="footerproduct" href="product_info.php/products_id/3851/3921/vA8+Series#modelinfo0" onClick="show_text(3851,modelinfo0);">ASUS(11)</a></td><td width="33%"></td><td width="33%"></td> </tr></table></td></tr><tr><td class="pageHeading"><h2><b/></h2></td></tr><tr><td class="welcome_index"></td></tr><tr><td></td></tr><tr><td><table width="98%" cellspacing="0" cellpadding="0"><tr><td class="pageHeading" height="30" align="center"><h1><b/><span itemprop="name"><a name="product1"></a>Original Brand New ASUS F3, F3J, A8 Series CPU Cooling Fan -- GC055515VH-A 4-PinS </span></h1></td></tr><tr><td class="welcome_index"><span itemprop="description"> Get your ASUS A8 Series Laptop Fan from battery-adapter.com today is free of charge for shipment. We supply high quality ASUS A8 Series Laptop CPU Fan with low price. We guarantee the ASUS A8 Series Laptop CPU Cooling Fan with a full three-months warranty from the date of purchase if the product(s) have any quality problem!</span></td></tr></table></td></tr><tr><td><div itemprop="offers" itemtype="http://schema.org/Offer"><table width="100%" cellspacing="0" cellpadding="0"><tr><td valign="top" class="main" width="31%" align="right"><table width="100%" cellpadding="2" cellspacing="1"><tr><td style="border-right:1px dashed; border-bottom:1px dashed;" width="48%" height="2" align="center"><table cellspacing="0" cellpadding="2"><tr><td align="center" class="smallText"></td></tr><tr><td align="center" class="smallText"><img src="images/mid/FASF3J.jpg" alt="Original Brand New ASUS F3, F3J, A8 Series CPU Cooling Fan -- GC055515VH-A 4-PinS" title=" Original Brand New ASUS F3, F3J, A8 Series CPU Cooling Fan -- GC055515VH-A 4-PinS "/>Click image to enlarge<noscript><img src="images/mid/FASF3J.jpg" alt="Original Brand New ASUS F3, F3J, A8 Series CPU Cooling Fan -- GC055515VH-A 4-PinS" title=" Original Brand New ASUS F3, F3J, A8 Series CPU Cooling Fan -- GC055515VH-A 4-PinS "/>Click image to enlarge </noscript></td></tr><tr><td align="center" class="price_product"><meta itemprop="priceCurrency" content="USD" /><span itemprop="price" content="10.96">$10.96</span></td></tr><tr><td align="center" style="font:bold 14px Verdana, Arial, Helvetica, sans-serif; color:#3D9D17;">Free Shipping</td></tr><tr><td align="center" style="font:bold 14px Verdana, Arial, Helvetica, sans-serif; color:#3D9D17;">Brand new,3 months warranty!</td></tr><tr><td align="center"></td></tr><tr><td align="center"><img src="images/ce.gif" alt="Authentication"/></td></tr></table></td><td valign="top" style="border-bottom:1px dashed;"><table width="100%" cellpadding="2" cellspacing="0"><tr><td valign="bottom" align="left" style=" font:bold 11px Verdana, Arial, Helvetica, sans-serif;color:#3B4F89; border-bottom:double #3B4F89;">ASUS A8 Series Laptop Accessory Information: </td></tr><tr><td class="main"><b/>Specification: Brand New ASUS F3, F3J, A8 Series CPU Cooling FANTested to be 100% working properly. <b/>Unit: PCS <b/>Type: Laptop CPU Fan<meta itemprop="itemCondition" itemtype="http://schema.org/OfferItemCondition" content="http://schema.org/NewCondition"/><b/>Condition: Brand New<b/>Warranty: 3 Months<b/>Power: DC5V 2.6W<b/>Info: Size(mm): 53 x 53 x 11, Wire Length: 65mm, (4 wires)4-pins connector</td></tr> <tr><td class="main"><b/>Availability:&nbsp;<meta itemprop="availability" content="http://schema.org/InStock"/>In Stock</td></tr><tr><td class="main"><b/>Payment | Delivery:&nbsp;PayPal | HongKong Registered Air Mail With Tracking Number, Free&nbsp;&nbsp;<a class="resources-newproduct" href="product_info.php/products_id/3851/3921/vA8+Series#bottom" title="Jump to detail of payment and shipping">[Detail?]</a></td></tr><tr><td height="30" align="left" valign="middle"><img src="includes/languages/english/images/buttons/button_in_cart.gif" alt="Add to Cart" title=" Add to Cart " width="93" height="24"/> </td></tr><tr><td><!-- tell_a_friend //--><table width="100%" cellspacing="0" cellpadding="1" class="infoBox"><tr><td><table width="100%" cellspacing="0" cellpadding="0" class="infoBoxContents"><tr><td><img src="images/pixel_trans.gif" alt="" width="100%" height="1"/></td></tr><tr><td align="left" class="boxText"><form name="tell_a_friend" action="https://www.battery-adapter.com/tell_a_friend.php" method="get"><a class="index_newlink" href="https://www.battery-adapter.com/product_reviews.php/products_id/3921"><img class="image_float" alt="View & Write Reviews" src="includes/languages/english/images/buttons/button_write_view.gif" /></a><a class="index_newlink" href="https://www.battery-adapter.com/ask_question.php/products_id/3921"><img class="image_float" alt="Ask a question" src="includes/languages/english/images/buttons/button_ask_question.gif" /></a></form></td></tr><tr><td><img src="images/pixel_trans.gif" alt="" width="100%" height="1"/></td></tr></table></td></tr></table><!-- tell_a_friend_eof //--></td></tr></table></td></tr></table></td></tr></table></div></td></tr><tr><td>&nbsp;</td></tr><tr><td> <div id="modelinfo1"><table width="99%" align="center" cellpadding="2" cellspacing="1" bgcolor="#F2E9D5"><tr><td colspan="2" class="replacement" height="25">&nbsp;<h2><b/>Compatible ASUS A8 Series Part Number and Models:</h2></td><td align="center"><a class="footerproduct" href="product_info.php/products_id/3851/3921/vA8+Series#brands1">Compatible Brands</a></td></tr><tr bgcolor="#FFFFFF"><td colspan="3" class="product_partno">Compatible Code</td></tr><tr bgcolor="#FFFFFF"><td width="34%" class="pro_in">13.B2239.F.GN</td><td width="33%" class="pro_in">DFB501005H20T(F7L8)</td><td width="33%" class="pro_in">GC055515VH-A</td></tr><tr bgcolor="#FFFFFF"><td width="34%" class="pro_in">KFB0505HHA-W376</td><td width="33%"></td><td width="33%"></td> </tr><tr bgcolor="#FFFFFF"><td colspan="3" class="product_partno">Fit Model</td></tr><tr bgcolor="#FFFFFF"><td width="34%" class="pro_in">A8 Series</td><td width="33%" class="pro_in">A8F</td><td width="33%" class="pro_in">A8Jm</td></tr><tr bgcolor="#FFFFFF"><td width="34%" class="pro_in">A8Sc</td><td width="33%" class="pro_in">F3 Series</td><td width="33%" class="pro_in">F3J</td></tr><tr bgcolor="#FFFFFF"><td width="34%" class="pro_in">M51 Series</td><td width="33%" class="pro_in">M51A Series</td><td width="33%" class="pro_in">M51E Series</td></tr><tr bgcolor="#FFFFFF"><td width="34%" class="pro_in">M51Kr Series</td><td width="33%" class="pro_in">M51SN Series</td><td width="33%" class="pro_in">M51Se Series</td></tr><tr bgcolor="#FFFFFF"><td width="34%" class="pro_in">M51Sr Series</td><td width="33%" class="pro_in">M51Va Series</td><td width="33%" class="pro_in">M51Vr Series</td></tr><tr bgcolor="#FFFFFF"><td width="34%" class="pro_in">X53S Series</td><td width="33%" class="pro_in">Z53 Series</td><td width="33%" class="pro_in">Z53J Series</td></tr><tr bgcolor="#FFFFFF"><td width="34%" class="pro_in">Z53X Series</td><td width="33%" class="pro_in">Z99 Series</td><td width="33%"></td></tr></table></div></td></tr><tr><td><table width="99%" align="center" cellpadding="2" cellspacing="1" bgcolor="#F2E9D5"><tr><td colspan="3" class="replacement" height="25"><a name="brands1" title="Compatible brands"></a><h2><b/>Compatible Brands (Select brand to view models)</h2></td></tr><tr bgcolor="#FFFFFF"><td class="pro_in"><a class="footerproduct" href="product_info.php/products_id/3851/3921/vA8+Series#modelinfo1" onClick="show_text(3921,modelinfo1);">ASUS(20)</a></td><td width="33%"></td><td width="33%"></td> </tr></table></td></tr><tr><td class="pageHeading"><h2><b/></h2></td></tr><tr><td class="welcome_index"></td></tr><tr><td></td></tr><tr><td><table width="99%" align="right"><tr><td class="main"><font color="#af7120" size="2"><strong>Shipping Information:</strong></font>We ship to worldwide range and the shipping is also free unless you request express delivery. The delivery to US will take about 6-10 business days, and to the other most countries usually takes about 7~14 business days.Normally, all orders are shipped from Hong Kong by HK post office registered air mail. You will get an email of shipping information including the tracking number once your order is shipped out from our warehouse.Please find the detail of the express as below:<table cellpadding="2" cellspacing="1" bgcolor="#CCCCCC" width="100%" class="main"><tr bgcolor="#FFFFFF"><td width="35%" class="main"><strong>Express Company</strong></td><td width="41%" class="main"><strong>Estimated Delivery Time</strong></td><td width="24%" class="main"><strong>Cost</strong></td></tr><tr bgcolor="#FFFFFF"><td class="main">EMS</td><td class="main">5-9 business days</td><td class="main">$18</td></tr><tr bgcolor="#FFFFFF" class="main"><td class="main">UPS</td><td class="main">3-6 business days</td><td class="main">$22</td></tr></table>If your address can"t be reached by above express company, please contact us by order&#64;battery-adapter.com and inform us of your express company.<a name="bottom"></a><font color="#af7120" size="2"><strong>About Payment:</strong></font><img src="images/paypal_accept.gif" alt="Paytype"/>We accept paypal paymentsNotice:You do not need to have a PayPal account to pay through Paypal.Don"t need to register a paypal account, Paypal accept the credit card directly now! Free, security and protect buyer.</td></tr></table></td></tr><tr><td class="pageHeading" ><h2><b/> &nbsp;<img src="images/heard_nav.gif" alt="Disclaimer"/> &nbsp;Disclaimer</h2></td></tr><tr><td class="main"><table><tr><td>&nbsp;</td><td class="main" style="color:#666666;">The products supplied by our Company are [replacement for] sold for use with certain products of computer manufacturers, and any reference to products or trademarks of such companies is purely for the purpose of identifying the computer manufacturers with which our products [are replacement for] may be used. Our Company and this Website are neither affiliated with, authorized by, licensed by, distributors for, nor related in any way to these computer manufacturers, nor are the products offered for sale through our Website manufactured by or sold with the authorization of the manufacturers of the computers with which our products [are replacement for] may be used.</td></tr></table></td></tr><tr><td align="right"><img src="images/top.gif" alt="Jump to top"/></td></tr></table></div>'
sp(any page with 3product and any page by 4product):
declare #start as int
declare #end as int
set #start=(select ROW_Numbers from
(SELECT
ROW_NUMBER() OVER (ORDER BY (SELECT 1000)) AS ROW_Numbers
, t.v.value('.','nvarchar(max)') as PN
FROM #htmlXML.nodes('div/table/tr[5]/td/div/table/tr/td') as t(v)
union
SELECT
ROW_NUMBER() OVER (ORDER BY (SELECT 1000)) AS ROW_Numbers,
t.v.value('.','nvarchar(max)') as PN
FROM #htmlXML.nodes('div/table/tr[8]/td/div/table/tr/td') as t(v)
union
SELECT
ROW_NUMBER() OVER (ORDER BY (SELECT 1000)) AS ROW_Numbers,
t.v.value('.','nvarchar(max)') as PN
FROM #htmlXML.nodes('div/table/tr[16]/td/div/table/tr/td') as t(v)
union
SELECT
ROW_NUMBER() OVER (ORDER BY (SELECT 1000)) AS ROW_Numbers,
t.v.value('.','nvarchar(max)') as PN
FROM #htmlXML.nodes('div/table/tr[24]/td/div/table/tr/td') as t(v)
)A
Where A.[Part Number ]='Compatible'
)
set #end=(select ROW_Numbers from
(SELECT
ROW_NUMBER() OVER (ORDER BY (SELECT 1000)) AS ROW_Numbers
, t.v.value('.','nvarchar(max)') as PN
FROM #htmlXML.nodes('div/table/tr[5]/td/div/table/tr/td') as t(v)
union
SELECT
ROW_NUMBER() OVER (ORDER BY (SELECT 1000)) AS ROW_Numbers,
t.v.value('.','nvarchar(max)') as PN
FROM #htmlXML.nodes('div/table/tr[8]/td/div/table/tr/td') as t(v)
union
SELECT
ROW_NUMBER() OVER (ORDER BY (SELECT 1000)) AS ROW_Numbers,
t.v.value('.','nvarchar(max)') as PN
FROM #htmlXML.nodes('div/table/tr[16]/td/div/table/tr/td') as t(v)
union
SELECT
ROW_NUMBER() OVER (ORDER BY (SELECT 1000)) AS ROW_Numbers,
t.v.value('.','nvarchar(max)') as PN
FROM #htmlXML.nodes('div/table/tr[24]/td/div/table/tr/td') as t(v)
)A
Where A.[Part Number ]='Fit Model')
SELECT
A. PN as ComPart from
(SELECT
ROW_NUMBER() OVER (ORDER BY (SELECT 1000)) AS ROW_Numbers
, t.v.value('.','nvarchar(max)') as PN
FROM #htmlXML.nodes('div/table/tr[5]/td/div/table/tr/td') as t(v))A
where A.ROW_Numbers>#start and A.ROW_Numbers<#end and A. PN!=''
union
SELECT
A. PN as ComPart from
(SELECT
ROW_NUMBER() OVER (ORDER BY (SELECT 1000)) AS ROW_Numbers
, t.v.value('.','nvarchar(max)') as PN
FROM #htmlXML.nodes('div/table/tr[8]/td/div/table/tr/td') as t(v)
union
SELECT
ROW_NUMBER() OVER (ORDER BY (SELECT 1000)) AS ROW_Numbers,
t.v.value('.','nvarchar(max)') as PN
FROM #htmlXML.nodes('div/table/tr[16]/td/div/table/tr/td') as t(v)
union
SELECT
ROW_NUMBER() OVER (ORDER BY (SELECT 1000)) AS ROW_Numbers,
t.v.value('.','nvarchar(max)') as PN
FROM #htmlXML.nodes('div/table/tr[24]/td/div/table/tr/td') as t(v))A
where A.ROW_Numbers>#start and A.ROW_Numbers<#end and A. PN !=''
my result any page only 1 pn and any page 2 pn and any page 4 pn and when have 1 pn first tr is tr[5] but when 2 pn first tr is tr[8] and etc....

Using multiple CTE's including a recursive CTE.
WITH CTE AS
(
SELECT
ROW_NUMBER() OVER (ORDER BY (SELECT 0)) AS rn,
t.v.value('.','nvarchar(max)') as value
FROM #htmlXML.nodes('div/table/tr[position()=(5,8,16,24)]/td/div/table/tr/td') as t(v)
),
COMPATS AS (
select CTE.value as ComCode, min(FITMODEL.rn) as rn_fitmodel
from CTE
join (select rn from CTE where value = 'Fit Model') FITMODEL
on (FITMODEL.rn > CTE.rn)
where CTE.rn in (select rn+1 from CTE where value = 'Compatible Code')
GROUP BY CTE.value
),
RECURSIVE_CTE AS (
select ComCode, CTE.rn, CTE.value
from COMPATS
JOIN CTE ON (COMPATS.rn_fitmodel + 1 = CTE.rn)
UNION ALL
select RECURSIVE_CTE.ComCode, CTE.rn, CTE.value
from RECURSIVE_CTE
JOIN CTE ON (RECURSIVE_CTE.rn + 1 = CTE.rn AND CTE.value <> '')
)
SELECT ComCode, value as ComPart
FROM RECURSIVE_CTE
ORDER BY ComCode, rn;

Related

Vue Transition not working when attempting to toggle between svgs. Working with vue transitions

Simple as the title suggests, I'm not sure why the transition is not working to toggle between both svgs.
What am I missing here? I wrapped the svgs in divs, but that didn't help at all.
Any advise would be greatly appreciated.
Cheers!
CodePen:
https://codepen.io/LovelyAndy/pen/MWmyzmm
Html
<div id="icon">
<transition name="fade" mode="out-in"><div v-if="show"
#click="show = !show">
<svg width="41" height="58" viewBox="0 0 41 58" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect x="0.5" width="40" height="40" rx="20" fill="#F9F9FF"/>
<path d="M14.9916 56.146C14.8796 56.2393 14.6696 56.3653 14.3616 56.524C14.0629 56.6827 13.6943 56.8227 13.2556 56.944C12.8169 57.0653 12.3316 57.1213 11.7996 57.112C10.9876 57.0933 10.2596 56.9487 9.61559 56.678C8.98093 56.398 8.43959 56.02 7.99159 55.544C7.55293 55.068 7.21693 54.522 6.98359 53.906C6.75026 53.29 6.63359 52.632 6.63359 51.932C6.63359 50.8867 6.84359 49.9627 7.26359 49.16C7.68359 48.3573 8.26693 47.7273 9.01359 47.27C9.76959 46.8127 10.6469 46.584 11.6456 46.584C12.3363 46.584 12.9476 46.6773 13.4796 46.864C14.0116 47.0507 14.4456 47.2513 14.7816 47.466L13.9836 49.384C13.7503 49.2067 13.4376 49.0247 13.0456 48.838C12.6629 48.642 12.2196 48.544 11.7156 48.544C11.1929 48.544 10.7029 48.6887 10.2456 48.978C9.79759 49.2673 9.43359 49.6593 9.15359 50.154C8.88293 50.6393 8.74759 51.1947 8.74759 51.82C8.74759 52.4827 8.87359 53.066 9.12559 53.57C9.37759 54.0647 9.73693 54.452 10.2036 54.732C10.6703 55.012 11.2163 55.152 11.8416 55.152C12.3923 55.152 12.8636 55.0633 13.2556 54.886C13.6476 54.7087 13.9463 54.522 14.1516 54.326L14.9916 56.146ZM19.2793 57.168C18.71 57.168 18.192 57.056 17.7253 56.832C17.268 56.5987 16.904 56.244 16.6333 55.768C16.3626 55.292 16.2273 54.6853 16.2273 53.948C16.2273 53.2573 16.3673 52.66 16.6473 52.156C16.9273 51.652 17.296 51.2647 17.7533 50.994C18.2106 50.714 18.696 50.574 19.2093 50.574C19.816 50.574 20.2733 50.672 20.5813 50.868C20.8986 51.064 21.1506 51.2787 21.3373 51.512L21.4633 50.882H23.2833V57H21.3233V56.244C21.23 56.3373 21.09 56.4587 20.9033 56.608C20.726 56.7573 20.502 56.888 20.2313 57C19.9606 57.112 19.6433 57.168 19.2793 57.168ZM19.8393 55.572C20.5206 55.572 21.0153 55.264 21.3233 54.648V53.15C21.2113 52.8513 21.0153 52.6133 20.7353 52.436C20.4646 52.2587 20.1426 52.17 19.7693 52.17C19.3493 52.17 18.9853 52.3287 18.6773 52.646C18.3693 52.954 18.2153 53.3553 18.2153 53.85C18.2153 54.1767 18.29 54.4707 18.4393 54.732C18.5886 54.9933 18.7846 55.1987 19.0273 55.348C19.2793 55.4973 19.55 55.572 19.8393 55.572ZM27.2909 57.126C26.7869 57.126 26.3156 57.0373 25.8769 56.86C25.4476 56.6827 25.0836 56.4353 24.7849 56.118L25.5969 55.04C25.8956 55.3107 26.1709 55.5067 26.4229 55.628C26.6843 55.74 26.9176 55.796 27.1229 55.796C27.3656 55.796 27.5663 55.7587 27.7249 55.684C27.8836 55.6093 27.9629 55.488 27.9629 55.32C27.9629 55.1613 27.8976 55.0353 27.7669 54.942C27.6456 54.8487 27.4869 54.774 27.2909 54.718C27.0949 54.6527 26.8849 54.5873 26.6609 54.522C26.1009 54.3447 25.6949 54.088 25.4429 53.752C25.2003 53.4067 25.0789 53.0333 25.0789 52.632C25.0789 52.324 25.1583 52.016 25.3169 51.708C25.4849 51.3907 25.7463 51.1293 26.1009 50.924C26.4649 50.7093 26.9316 50.602 27.5009 50.602C28.0143 50.602 28.4483 50.6533 28.8029 50.756C29.1576 50.8587 29.4936 51.0267 29.8109 51.26L29.0689 52.408C28.8916 52.268 28.6909 52.1513 28.4669 52.058C28.2523 51.9553 28.0516 51.8993 27.8649 51.89C27.6129 51.8807 27.4169 51.9273 27.2769 52.03C27.1369 52.1233 27.0669 52.2353 27.0669 52.366C27.0576 52.5433 27.1229 52.6833 27.2629 52.786C27.4123 52.8887 27.5989 52.968 27.8229 53.024C28.0469 53.08 28.2663 53.1453 28.4809 53.22C28.9196 53.3693 29.2696 53.584 29.5309 53.864C29.7923 54.1347 29.9229 54.4987 29.9229 54.956C29.9229 55.3293 29.8249 55.684 29.6289 56.02C29.4423 56.3467 29.1529 56.6127 28.7609 56.818C28.3783 57.0233 27.8883 57.126 27.2909 57.126ZM32.1386 48.194H34.0986V50.854H35.5826V52.38H34.0986V57H32.1386V52.38H31.1866V50.854H32.1386V48.194Z" fill="#1A0050"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M15.6 17.9C16.2627 17.9 16.8 17.3627 16.8 16.7C16.8 16.0373 16.2627 15.5 15.6 15.5C14.9373 15.5 14.4 16.0373 14.4 16.7C14.4 17.3627 14.9373 17.9 15.6 17.9ZM15.6 20.3C17.5882 20.3 19.2 18.6882 19.2 16.7C19.2 14.7118 17.5882 13.1 15.6 13.1C13.6118 13.1 12 14.7118 12 16.7C12 18.6882 13.6118 20.3 15.6 20.3Z" fill="#712EFF"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M15.66 21.2C14.6659 21.2 13.86 22.0059 13.86 23L13.86 24.8C13.86 25.4628 13.3227 26 12.6599 26C11.9972 26 11.46 25.4628 11.46 24.8L11.46 23C11.46 20.6804 13.3404 18.8 15.66 18.8C17.9796 18.8 19.86 20.6804 19.86 23V23.6C19.86 24.2628 19.3227 24.8 18.66 24.8C17.9972 24.8 17.46 24.2628 17.46 23.6V23C17.46 22.0059 16.6541 21.2 15.66 21.2Z" fill="#712EFF"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M26.3998 17.9C25.737 17.9 25.1998 17.3627 25.1998 16.7C25.1998 16.0373 25.737 15.5 26.3998 15.5C27.0624 15.5 27.5998 16.0373 27.5998 16.7C27.5998 17.3627 27.0624 17.9 26.3998 17.9ZM26.3998 20.3C24.4115 20.3 22.7998 18.6882 22.7998 16.7C22.7998 14.7118 24.4115 13.1 26.3998 13.1C28.388 13.1 29.9998 14.7118 29.9998 16.7C29.9998 18.6882 28.388 20.3 26.3998 20.3Z" fill="#712EFF"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M26.3396 21.2C27.3337 21.2 28.1396 22.0059 28.1396 23V24.8C28.1396 25.4628 28.6769 26 29.3396 26C30.0024 26 30.5396 25.4628 30.5396 24.8V23C30.5396 20.6804 28.6592 18.8 26.3396 18.8C24.02 18.8 22.1396 20.6804 22.1396 23V23.6C22.1396 24.2628 22.6769 24.8 23.3396 24.8C24.0024 24.8 24.5396 24.2628 24.5396 23.6V23C24.5396 22.0059 25.3456 21.2 26.3396 21.2Z" fill="#712EFF"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M21.0604 24.5C20.0663 24.5 19.2604 25.3059 19.2604 26.3L19.2604 28.1C19.2604 28.7628 18.7231 29.3 18.0603 29.3C17.3976 29.3 16.8604 28.7628 16.8604 28.1L16.8604 26.3C16.8604 23.9804 18.7408 22.1 21.0604 22.1C23.38 22.1 25.2604 23.9804 25.2604 26.3V28.1C25.2604 28.7628 24.7232 29.3 24.0604 29.3C23.3977 29.3 22.8604 28.7628 22.8604 28.1V26.3C22.8604 25.3059 22.0545 24.5 21.0604 24.5Z" fill="#712EFF"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M21.0004 21.2C21.6632 21.2 22.2004 20.6628 22.2004 20C22.2004 19.3373 21.6632 18.8 21.0004 18.8C20.3377 18.8 19.8004 19.3373 19.8004 20C19.8004 20.6628 20.3377 21.2 21.0004 21.2ZM21.0004 23.6C22.9887 23.6 24.6004 21.9883 24.6004 20C24.6004 18.0118 22.9887 16.4 21.0004 16.4C19.0122 16.4 17.4004 18.0118 17.4004 20C17.4004 21.9883 19.0122 23.6 21.0004 23.6Z" fill="#712EFF"/>
</svg>
</div> <div v-else
#click="show = !show" >
<svg width="24" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M6.6 9.9C7.26274 9.9 7.8 9.36274 7.8 8.7C7.8 8.03726 7.26274 7.5 6.6 7.5C5.93726 7.5 5.4 8.03726 5.4 8.7C5.4 9.36274 5.93726 9.9 6.6 9.9ZM6.6 12.3C8.58822 12.3 10.2 10.6882 10.2 8.7C10.2 6.71178 8.58822 5.1 6.6 5.1C4.61178 5.1 3 6.71178 3 8.7C3 10.6882 4.61178 12.3 6.6 12.3Z" fill="#712EFF"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M6.66002 13.2C5.66588 13.2 4.85997 14.0059 4.85997 15L4.85996 16.8C4.85996 17.4628 4.3227 18 3.65995 18C2.99721 18 2.45996 17.4628 2.45996 16.8L2.45997 15C2.45998 12.6804 4.34041 10.8 6.66002 10.8C8.9796 10.8 10.86 12.6804 10.86 15V15.6C10.86 16.2628 10.3227 16.8 9.65998 16.8C8.99725 16.8 8.45998 16.2628 8.45998 15.6V15C8.45998 14.0059 7.65411 13.2 6.66002 13.2Z" fill="#712EFF"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M17.4003 9.9C16.7375 9.9 16.2003 9.36274 16.2003 8.7C16.2003 8.03726 16.7375 7.5 17.4003 7.5C18.0629 7.5 18.6003 8.03726 18.6003 8.7C18.6003 9.36274 18.0629 9.9 17.4003 9.9ZM17.4003 12.3C15.412 12.3 13.8003 10.6882 13.8003 8.7C13.8003 6.71178 15.412 5.1 17.4003 5.1C19.3885 5.1 21.0003 6.71178 21.0003 8.7C21.0003 10.6882 19.3885 12.3 17.4003 12.3Z" fill="#712EFF"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M17.3401 13.2C18.3342 13.2 19.1401 14.0059 19.1401 15V16.8C19.1401 17.4628 19.6774 18 20.3401 18C21.0029 18 21.5401 17.4628 21.5401 16.8V15C21.5401 12.6804 19.6597 10.8 17.3401 10.8C15.0205 10.8 13.1401 12.6804 13.1401 15V15.6C13.1401 16.2628 13.6774 16.8 14.3401 16.8C15.0029 16.8 15.5401 16.2628 15.5401 15.6V15C15.5401 14.0059 16.3461 13.2 17.3401 13.2Z" fill="#712EFF"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M12.0599 16.5C11.0658 16.5 10.2599 17.3059 10.2599 18.3L10.2599 20.1C10.2599 20.7628 9.7226 21.3 9.05985 21.3C8.39712 21.3 7.85986 20.7628 7.85986 20.1L7.85988 18.3C7.85989 15.9804 9.74031 14.1 12.0599 14.1C14.3795 14.1 16.2599 15.9804 16.2599 18.3V20.1C16.2599 20.7628 15.7227 21.3 15.0599 21.3C14.3972 21.3 13.8599 20.7628 13.8599 20.1V18.3C13.8599 17.3059 13.054 16.5 12.0599 16.5Z" fill="#712EFF"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M11.9999 13.2C12.6627 13.2 13.1999 12.6628 13.1999 12C13.1999 11.3373 12.6627 10.8 11.9999 10.8C11.3372 10.8 10.7999 11.3373 10.7999 12C10.7999 12.6628 11.3372 13.2 11.9999 13.2ZM11.9999 15.6C13.9882 15.6 15.5999 13.9883 15.5999 12C15.5999 10.0118 13.9882 8.4 11.9999 8.4C10.0117 8.4 8.3999 10.0118 8.3999 12C8.3999 13.9883 10.0117 15.6 11.9999 15.6Z" fill="#712EFF"/>
</svg>
</div>
</transition>
</div>
CSS
body {
align-items: center;
background-color: white;
display: flex;
flex-direction: column;
justify-content: center;
height: 100vh;
}
.fade-enter-active, .fade-leave-active {
transition: opacity .5s
}
.fade-enter, .fade-leave-to {
opacity: 0
}
You are missing a key.
When toggling between elements that have the same tag name, you must tell Vue that they are distinct elements by giving them unique key attributes. Otherwise, Vue’s compiler will only replace the content of the element for efficiency. Even when technically unnecessary though, it’s considered good practice to always key multiple items within a component.
Enter/Leave & List Transitions
Example:
<script>
export default {
data() {
return {
show: false,
}
},
}
</script>
body {
align-items: center;
background-color: white;
display: flex;
flex-direction: column;
justify-content: center;
height: 100vh;
}
.fade-enter-active, .fade-leave-active {
transition: opacity .5s
}
.fade-enter, .fade-leave-to {
opacity: 0
}
<div id="icon">
<transition name="fade" mode="out-in">
<div v-if="show" key="one" #click="show = !show">
svg...
</div>
<div v-else key="two" #click="show = !show">
svg...
</div>
</transition>
</div>

Preserve table cell line breaks in Sphinx processing of reStructuredText

I have a reStructuredText table with a row like this:
+------+-----------------------------+
| Mask | The bit mask: |
| | [bit 0] Description of bit0 |
| | [bit 1] And bit1 |
+------+-----------------------------+
The cell when produced by Sphinx (HTML as example) is this:
<td><p>The bit mask:
[bit 0] Description of bit0
[bit 1] And bit1</p></td>
What I would like to be produced is this (or similar), where a line break is forced at least before every new line:
<td><p>The bit mask:
<br>[bit 0] Description of bit0
<br>[bit 1] And bit1</p></td>
Is there a way I can configure Sphinx to respect the lines in a reStructuredText table cell?
(For reference, here is the whole table as currently produced:)
<table class="docutils align-default">
<colgroup>
<col style="width: 17%" />
<col style="width: 83%" />
</colgroup>
<tbody>
<tr class="row-odd">
<td>
<p>Mask</p>
</td>
<td>
<p>The bit mask:
[bit 0] Description of bit0
[bit 1] And bit1
</p>
</td>
</tr>
</tbody>
</table>
Generally there are two easy ways to guarantee a line break or alignment in reST.
1. Using Paragraphs, the following:
+------+-----------------------------+
| Mask | The bit mask: |
| | |
| | [bit 0] Description of bit0 |
| | |
| | [bit 1] And bit1 |
| | |
+------+-----------------------------+
Will give:
<table class="docutils align-default">
<tbody>
<tr class="row-odd">
<td>
<p>Mask</p>
</td>
<td>
<p>The bit mask:</p>
<p>[bit 0] Description of bit0</p>
<p>[bit 1] And bit1</p>
</td>
</tr>
</tbody>
</table>
2. Using Line Blocks, the following:
+------+-------------------------------+
| Mask | | The bit mask: |
| | | [bit 0] Description of bit0 |
| | | [bit 1] And bit1 |
+------+-------------------------------+
Will give:
</table>
<tbody>
<tr class="row-odd">
<td>
<p>Mask</p>
</td>
<td>
<div class="line-block">
<div class="line">The bit mask:</div>
<div class="line">[bit 0] Description of bit0</div>
<div class="line">[bit 1] And bit1</div>
</div>
</td>
</tr>
</tbody>
</table>
The resulting <div class="line"></div> will work like a paragraph and also keep alignment. This is guaranteed by the reST specification, so even if your output is not HTML there should be mechanisms in place to guarantee the result will be consistent.

How can I make all values of one identifier the same based a on value in a row?

SELECT a.IDENTIFIER,
a.NAME,
a.CATEGORY,
b.IDENTIFIER_TYPE,
b.NAME,
CASE
WHEN b.IDENTIFIER_TYPE = 111 THEN 'PRESENT'
ELSE 'NOT PRESENT'
END AS HAS111
FROM TABLE_A a
LEFT JOIN IDENTIFIER_TYPE_TABLE b ON a.IDENTIFIER = b.IDENTIFIER
WHERE a.IDENTIFIER IN (1, 2, 3, 4)
;
Here is the code I'm using, and the data I'm getting is:
But I want the data to look like this:
Basically, I need this:
td {
text-align: center;
}
<table>
<tbody>
<tr>
<td>IDENTIFIER</td>
<td>NAME</td>
<td>CATEGORY</td>
<td>IDENTIFIER_TYPE</td>
<td>HAS111</td>
</tr>
<tr>
<td>123</td>
<td>item123</td>
<td>1</td>
<td>778</td>
<td>not present</td>
</tr>
<tr>
<td>123</td>
<td>item123</td>
<td>1</td>
<td>127</td>
<td>not present</td>
</tr>
<tr>
<td>123</td>
<td>item123</td>
<td>1</td>
<td>137</td>
<td>not present</td>
</tr>
<tr>
<td>456</td>
<td>item456</td>
<td>1</td>
<td>122</td>
<td>not present</td>
</tr>
<tr>
<td>456</td>
<td>item456</td>
<td>2</td>
<td>87</td>
<td>not present</td>
</tr>
<tr>
<td>456</td>
<td>item456</td>
<td>2</td>
<td>444</td>
<td>not present</td>
</tr>
<tr>
<td>789</td>
<td>item789</td>
<td>2</td>
<td>289</td>
<td>present</td>
</tr>
<tr>
<td>789</td>
<td>item789</td>
<td>2</td>
<td>111</td>
<td>present</td>
</tr>
<tr>
<td>789</td>
<td>item789</td>
<td>2</td>
<td>75</td>
<td>present</td>
</tr>
</tbody>
</table>
You see item789 has 111 in one of the rows, therefore I need all the other rows to say "present" for item789. The others don't have 111, so they have no 111 present. Does this make sense?
You can use EXISTS :
SELECT a.IDENTIFIER, a.NAME, a.CATEGORY, b.IDENTIFIER_TYPE, b.NAME,
(CASE WHEN EXISTS (SELECT 1
FROM IDENTIFIER_TYPE_TABLE b1
WHERE a.IDENTIFIER = b1.IDENTIFIER AND
b1.IDENTIFIER_TYPE = 111
)
THEN 'PRESENT' ELSE 'NOT PRESENT'
END) AS HAS111
FROM TABLE_A a LEFT JOIN
IDENTIFIER_TYPE_TABLE b
ON a.IDENTIFIER = b.IDENTIFIER
WHERE a.IDENTIFIER IN (1, 2, 3, 4);
Use window functions:
SELECT a.IDENTIFIER, a.NAME, a.CATEGORY,
b.IDENTIFIER_TYPE, b.NAME,
(CASE WHEN b.num_111 > 0 THEN 'PRESENT'
ELSE 'NOT PRESENT'
END) AS HAS111
FROM TABLE_A a LEFT JOIN
(SELECT b.*,
SUM(CASE WHEN b.IDENTIFIER_TYPE = 111 THEN 1 ELSE 0 END) OVER (PARTITION BY b.IDENTIFIER) as num_111
FROM IDENTIFIER_TYPE_TABLE b
) b
ON a.IDENTIFIER = b.IDENTIFIER
WHERE a.IDENTIFIER IN (1, 2, 3, 4);
Or don't use a subquery:
SELECT a.IDENTIFIER, a.NAME, a.CATEGORY,
b.IDENTIFIER_TYPE, b.NAME,
(CASE WHEN SUM(CASE WHEN b.IDENTIFIER_TYPE = 111 THEN 1 ELSE 0 END) > 0 THEN 'PRESENT'
ELSE 'NOT PRESENT'
END) AS HAS111
FROM TABLE_A a LEFT JOIN
IDENTIFIER_TYPE_TABLE b
ON a.IDENTIFIER = b.IDENTIFIER
WHERE a.IDENTIFIER IN (1, 2, 3, 4);
You will want to left join to your table again for just presents:
SELECT a.IDENTIFIER,
a.NAME,
a.CATEGORY,
b.IDENTIFIER_TYPE,
b.NAME,
iif( b.identifier is null,'Not Present','Present') as HAS111
FROM TABLE_A a
left join (Select distinct identifier table_A where type = 111) b on a.identifier=b.identifier

SQL UNION Not Working

I'm using SQL Server 2014 and have two table: ApplicationProjectLO and V_SIP_ALLSTAFF:
Table ApplicationProjectLO:
|---------------------|---------------------------|
| StaffEmailId | Type |
|---------------------|---------------------------|
| chinkim1 | L |
|---------------------|---------------------------|
| kandiah1 | A |
|---------------------|---------------------------|
Table V_SIP_ALLSTAFF
|---------------------|----------------|-------------------|---------------|
| lOGINID | displayname | Email Address |MainOfficeTelNo|
|---------------------|----------------|---------------- |-------------- |
| chinkim1 | james | 1 | 5 |
|---------------------|----------------|---------------- |---------------|
| kandiah1 | hoho | 2 | 8 |
|---------------------|----------------|---------------- |---------------|
I would like to display the information based on 'Type'.
So if the StaffEmailId match the LONGINID and the type is A, the information of type A (that is hoho, 2, and 8) must be displayed, and if type is L then it james, 1, and 5 must be displayed.
I tried to use UNION and UNION ALL to run two select statement in one query but it only return type=L result based on this query:
SELECT
vsa.displayname NameofLiaisonOfficer,
vsa.EmailAddress LOEmail,
'(65)' +' '+ convert(varchar, vsa.MainOfficeTelNo ) as LOContactNo,
vsa.MainOfficeTelNo GeneralOfficeConatctNo
FROM ApplicationProjectLo ap
INNER JOIN V_SIP_ALLSTAFF vsa ON ap.StaffEmailId = vsa.LOGINID
WHERE ap.Type = 'L'
UNION ALL
SELECT
vsa.displayname NameofAlternateLiaisonOfficer,
vsa.EmailAddress AlternateLOEmail,
'(65)' +' '+ convert(varchar, vsa.MainOfficeTelNo ) as AlternateLOContactNo,
vsa.MainOfficeTelNo GeneralOfficeConatctNo
FROM ApplicationProjectLo ap
INNER JOIN V_SIP_ALLSTAFF vsa ON ap.StaffEmailId = vsa.LOGINID
WHERE ap.Type = 'A'
MVC View:
<tr>
<td colspan="3">
<strong>Name of Liaison Officer</strong>
<br />
<br /> #Html.DisplayFor(m => m.TPInformationDetails.NameofLiaisonOfficer)
</td>
#*
<td>
<strong>Room Number</strong>
<br />
<br />
</td>*#
<td>
<strong>Contact Number</strong>
<br />
<br /> #Html.DisplayFor(m => m.TPInformationDetails.LOContactNo)
</td>
<td>
<strong>Email Address</strong>
<br />
<br /> #Html.DisplayFor(m => m.TPInformationDetails.LOEmail)
</td>
</tr>
<!-- Table Row -->
<tr class="even">
<td colspan="3">
<strong>Name of Alternate Liaison Officer</strong>
<br />
<br /> #Html.DisplayFor(m => m.TPInformationDetails.NameofAlternateLiaisonOfficer)
</td>
<td>
<strong>Contact Number</strong>
<br />
<br /> #Html.DisplayFor(m => m.TPInformationDetails.AlternateLOContactNo)
</td>
<td>
<strong>Email Address</strong>
<br />
<br /> #Html.DisplayFor(m => m.TPInformationDetails.AlternateLOEmail)
</td>
</tr>
<!-- Table Row -->
Just dispense wth the WHERE:
SELECT vsa.displayname as NameofLiaisonOfficer,
vsa.EmailAddress LOEmail,
'(65)' +' '+ convert(varchar, vsa.MainOfficeTelNo ) as LOContactNo,
vsa.MainOfficeTelNo GeneralOfficeConatctNo
FROM ApplicationProjectLo ap INNER JOIN
V_SIP_ALLSTAFF vsa
ON ap.StaffEmailId = vsa.LOGINID;
Or use a WHERE that includes both types:
SELECT vsa.displayname as NameofLiaisonOfficer,
vsa.EmailAddress LOEmail,
'(65)' +' '+ convert(varchar, vsa.MainOfficeTelNo ) as LOContactNo,
vsa.MainOfficeTelNo GeneralOfficeConatctNo
FROM ApplicationProjectLo ap INNER JOIN
V_SIP_ALLSTAFF vsa
ON ap.StaffEmailId = vsa.LOGINID;
WHERE ap.Type IN ('A', 'L');
That said, it is unclear why your query -- although over-complicated -- is not returning both types. One possibility is that you are using a national character set and the "A" is not really an "A".
Use the below query to display the result with type 'L' and 'A'.
SELECT
vsa.displayname NameofLiaisonOfficer,
vsa.EmailAddress LOEmail,
'(65)' +' '+ convert(varchar, vsa.MainOfficeTelNo ) as LOContactNo,
vsa.MainOfficeTelNo GeneralOfficeConatctNo
FROM ApplicationProjectLo ap
INNER JOIN V_SIP_ALLSTAFF vsa ON ap.StaffEmailId = vsa.LOGINID
WHERE ap.Type IN ('L','A')
ORDER BY ap.Type desc
SELECT
vsa.displayname NameofLiaisonOfficer,
vsa.EmailAddress LOEmail,
'(65)' +' '+ convert(varchar, vsa.MainOfficeTelNo ) as LOContactNo,
vsa.MainOfficeTelNo GeneralOfficeConatctNo
FROM ApplicationProjectLo ap
INNER JOIN V_SIP_ALLSTAFF vsa ON ap.StaffEmailId = vsa.LOGINID
WHERE ap.Type IN ('A', 'L')
You need a JOIN, not an UNION. JOIN combines columns from two tables based on common key field(s).
SELECT a.field1, b.field1, b.field2 FROM table1 a JOIN table2 b ON a.keyfield=b.keyfield;
const string _sqlODetails = #"SELECT vsa.displayname NameofLiaisonOfficer,
vsa.EmailAddress LOEmail,
'(65)' +' '+ convert(varchar, vsa.MainOfficeTelNo ) as LOContactNo,
vsa.MainOfficeTelNo GeneralOfficeConatctNo
FROM ApplicationProjectLo ap
INNER JOIN V_SIP_ALLSTAFF vsa ON ap.StaffEmailId = vsa.LOGINID
WHERE ap.Type = 'L'";
using (var connection = Db.SqlServer())
{
tpOdetails = connection
.Query<TPInformationDetails>(_sqlODetails)
.FirstOrDefault();
}
const string _sqlADetails = #"SELECT vsa.displayname NameofAlternateLiaisonOfficer,
vsa.EmailAddress AlternateLOEmail,
'(65)' +' '+ convert(varchar, vsa.MainOfficeTelNo ) as AlternateLOContactNo,
vsa.MainOfficeTelNo GeneralOfficeConatctNo
FROM ApplicationProjectLo ap
INNER JOIN V_SIP_ALLSTAFF vsa ON ap.StaffEmailId = vsa.LOGINID
WHERE ap.Type = 'A'";
using (var connection = Db.SqlServer())
{
tpAdetails = connection
.Query<TPInformationDetails>(_sqlADetails)
.FirstOrDefault();
}

Finding columns with highest value among other columns in SQL

I have a table that looks like this:
table,
th,
td {
border: 1px solid black;
<table>
<tr>
<th>Customer</th>
<th>Category 1</th>
<th>Category 2</th>
<th>Category 3</th>
<th>Category 4</th>
</tr>
<tr>
<td>aaaaa#aaa.com</td>
<td>0</td>
<td>563</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td>bbbb#bbb.com</td>
<td>33</td>
<td>31</td>
<td>38</td>
<td>13</td>
</tr>
<tr>
<td>cccc#ccc.com</td>
<td>108</td>
<td>0</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td>dddd#ddd.com</td>
<td>0</td>
<td>7</td>
<td>0</td>
<td>11</td>
</tr>
</table>
I am trying to insert a new column named "BestCategory" that will show the name of the category that has the highest value in between them.
I have tried to use GREATEST but it's not accepted in my system.
Can you guys help me?
First you have to use UNPIVOT to calculate the maxValue for each row
Then use a CASE to select what is the BestCategory.
Sql Fiddle Demo
WITH maxValues as
(
select
[Customer], Max(Amount) as TheMax
from
Customer
UNPIVOT (Amount for AmountCol in
([Category 1], [Category 2], [Category 3], [Category 4])) as unpvt
group by [Customer]
)
select
Customer.[Customer], [Category 1], [Category 2], [Category 3], [Category 4],
TheMax,
Case
WHEN [Category 1] = TheMax THEN '[Category 1]'
WHEN [Category 2] = TheMax THEN '[Category 2]'
WHEN [Category 3] = TheMax THEN '[Category 3]'
ELSE '[Category 4]'
END as BestCategory
from Customer
inner join maxValues
on Customer.[Customer] = maxValues.[Customer]
OUTPUT
| Customer | Category 1 | Category 2 | Category 3 | Category 4 | TheMax | BestCategory |
|---------------|------------|------------|------------|------------|--------|--------------|
| aaaaa#aaa.com | 0 | 563 | 0 | 0 | 563 | [Category 2] |
| bbbb#bbb.com | 33 | 31 | 38 | 13 | 38 | [Category 3] |
| cccc#ccc.com | 108 | 0 | 0 | 0 | 108 | [Category 1] |
| dddd#ddd.com | 0 | 7 | 0 | 11 | 11 | [Category 4] |
If you want the columnname in the "greatest field" you could use the idea in this sqlfiddle example
It selects the columnname with the greatest value per row
SELECT CASE
WHEN [category 1] > [category 2]
AND [category 1] > [category 3]
AND [category 1] > [category 4]
THEN '[Category 1]'
ELSE CASE
WHEN [category 2] > [category 1]
AND [category 2] > [category 3]
AND [category 2] > [category 4]
THEN '[Category 2]'
ELSE CASE
WHEN [category 3] > [category 1]
AND [category 3] > [category 2]
AND [category 3] > [category 4]
THEN '[Category 3]'
ELSE '[category 4]'
END
END
END
FROM customer