Sub Price_list_General(customer As String)
Dim cadena As String =""
Dim otrac As String=""
otrac=cadenaR(customer)
cadena = "Select distinct(c.account) As customer,(Select id_break from price_break pp where o.id_break=pp.id_break) As id_break,(Select quantity from price_break pp where o.id_break=pp.id_break) As quantity,i.category,i.itemcode As ITEMCODE,I.description As DESCRIPTION, I.pricing As PRICING,(Select price from price_break pp where o.id_break=pp.id_break) As price_break,(Select ONHAND from availability AA where o.items_itemcode=AA.itemcode)As Availability,o.cantidad As ORDEN, ' ' AS FAVORITO" _
&" FROM CUSTOMERS C" _
&" INNER JOIN ORDEN O" _
&" ON C.ACCOUNT=O.CUSTOMERS_ACCOUNT" _
&" INNER JOIN ITEMS I " _
&" ON O.ITEMS_ITEMCODE=I.ITEMCODE" _
&" LEFT JOIN AVAILABILITY A" _
&" ON I.ITEMCODE=A.itemcode" _
&" LEFT JOIN PRICE_BREAK pb" _
&" ON I.ITEMCODE=PB.ITEMCODE" _
&" WHERE customer="& customer _
&" AND I.ITEMCODE NOT IN (" _
&" select DISTINCT(I.ITEMCODE) " _
&" FROM CUSTOMERS C" _
&" INNER JOIN ORDEN O" _
&" ON C.ACCOUNT=O.CUSTOMERS_ACCOUNT" _
&" INNER JOIN ITEMS I " _
&" ON O.ITEMS_ITEMCODE=I.ITEMCODE" _
&" INNER JOIN FAVORITO F " _
&" ON c.account=f.customers_account" _
&" AND F.ITEMS_ITEMCODE=I.ITEMCODE" _
&" LEFT JOIN AVAILABILITY A" _
&" ON I.ITEMCODE=A.itemcode" _
&" LEFT JOIN PRICE_BREAK pb" _
&" ON I.ITEMCODE=PB.ITEMCODE" _
&" WHERE C.account=" & customer _
&" )" _
&" UNION ALL" _
&" select distinct(c.account) as customer,(Select id_break from price_break pp where f.id_break=pp.id_break) As id_break,(Select quantity from price_break pp where f.id_break=pp.id_break) As quantity,i.category,i.itemcode as ITEMCODE,I.description AS DESCRIPTION, I.pricing AS PRICING,(select price from price_break pp where F.id_break=pp.id_break) as price_break,(select ONHAND from availability AA where F.items_itemcode=AA.itemcode)as Availability,' ' AS ORDEN, f.favorito AS FAVORITO" _
&" FROM CUSTOMERS C" _
&" INNER JOIN FAVORITO F" _
&" ON C.ACCOUNT=F.CUSTOMERS_ACCOUNT" _
&" INNER JOIN ITEMS I " _
&" ON F.ITEMS_ITEMCODE=I.ITEMCODE" _
&" LEFT JOIN AVAILABILITY A" _
&" ON I.ITEMCODE=A.itemcode" _
&" LEFT JOIN PRICE_BREAK pb" _
&" ON I.ITEMCODE=PB.ITEMCODE" _
&" WHERE customer=" & customer _
&" AND I.ITEMCODE NOT IN (" _
&" select DISTINCT(I.ITEMCODE) " _
&" FROM CUSTOMERS C" _
&" INNER JOIN ORDEN O" _
&" ON C.ACCOUNT=O.CUSTOMERS_ACCOUNT" _
&" INNER JOIN ITEMS I " _
&" ON O.ITEMS_ITEMCODE=I.ITEMCODE" _
&" INNER JOIN FAVORITO F " _
&" ON c.account=f.customers_account" _
&" AND F.ITEMS_ITEMCODE=I.ITEMCODE" _
&" LEFT JOIN AVAILABILITY A" _
&" ON I.ITEMCODE=A.itemcode" _
&" LEFT JOIN PRICE_BREAK pb" _
&" ON I.ITEMCODE=PB.ITEMCODE" _
&" WHERE C.account=" & customer _
&" )" _
&" union all" _
&" select distinct(c.account) as customer,(Select id_break from price_break pp where o.id_break=pp.id_break) As id_break,(Select quantity from price_break pp where o.id_break=pp.id_break) As quantity,i.category,i.itemcode as ITEMCODE,I.description AS DESCRIPTION, I.pricing AS PRICING,(select price from price_break pp where F.id_break=pp.id_break)as price_break,A.ONHAND as Availability,o.cantidad AS ORDEN, f.favorito AS FAVORITO" _
&" FROM CUSTOMERS C" _
&" INNER JOIN ORDEN O" _
&" ON C.ACCOUNT=O.CUSTOMERS_ACCOUNT" _
&" INNER JOIN ITEMS I " _
&" ON O.ITEMS_ITEMCODE=I.ITEMCODE" _
&" INNER JOIN FAVORITO F " _
&" ON c.account=f.customers_account" _
&" AND F.ITEMS_ITEMCODE=I.ITEMCODE" _
&" LEFT JOIN AVAILABILITY A" _
&" ON I.ITEMCODE=A.itemcode" _
&" LEFT JOIN PRICE_BREAK pb" _
&" ON I.ITEMCODE=PB.ITEMCODE" _
&" WHERE C.account=" & customer _
&" union all" _
&" SELECT CUSTOMER,id_break,quantity,category,ITEMCODE,DESCRIPTION,PRICING,PRICE_BREAK,AVAILABILITY,ORDEN,FAVORITO" _
&" FROM" _
&" (SELECT DISTINCT(I.ITEMCODE) AS ITEMCODE,(Select id_break from price_break pp where f.id_break=pp.id_break) As id_break,pb.quantity,i.category as category,(select customers_account from orden where pb.id_break=orden.id_break) as customer , I.description AS DESCRIPTION, I.pricing AS PRICING ,pb.price aS price_break ,A.ONHAND as Availability ,' ' orden,(select favorito from FAVORITO where pb.id_break=favorito.id_break AND i.itemcode=favorito.items_itemcode AND CUSTOMERS_ACCOUNT="&customer&") As FAVORITO" _
&" FROM ITEMS I" _
&" LEFT join price_break pb" _
&" on i.itemcode=pb.itemcode" _
&" LEFT JOIN AVAILABILITY A" _
&" ON I.ITEMCODE=A.ITEMCODE" _
&" LEFT JOIN FAVORITO F" _
&" ON I.ITEMCODE=F.ITEMS_ITEMCODE" _
&" where customer IS NULL" _
&" )A" _
&" where favorito is not 1" _
&" AND ITEMCODE NOT IN("&otrac&")"
Return cadena
End Sub