display only sql fields having values in asp - sql-server-2008

i am having a asp web page that retrieves value from sql...it shows the fields without having values..is there anyway to display only the fields having values..this is my table
[] [][] "Mfg Dt and Exp Dt as per Annexure enclosed"
this square brackets contain null values..if the field is empty then this square bracket will not come
in first row i am having 2 sets of square brackets and in second row i am having the values in 2 sets..i need to show only the square bracket having values like in the second row..if the value is empty then dont want to show that empty brackets.
sql query
select I.[Old Product Code], I.[Trade Name], I.[Short Name], SUM(Quantity) as Qty,I.[Base Box UOM], SIH.[Customer Marks - 1] ,SIH.[Bill-to Name],SIH.[Bill-to Address], SIH.[Ship-to Name], SIH.[Ship-to Address], SIH.[Ship-to Address 2] ,SIH.[Ship-to City], SIH.[Ship-to Post Code],SIH.[Country of Origin of Goods],SIH.[Bill-to Address 2] ,SIH.[Bill-to City] , SIH.[Bill-to Post Code], CR.Name ,C.Contact,SIH.[Total Boxes], CASE when SIL.[Dimension Group Code] = 'IOL' then I.[Group Description]
END ,
CASE
when I.[EPCG License] = 1 then 'EPCG'
end,
case
when SIL.[Dimension Group Code] = 'IOL' then 'DEEC'
when I.[DEEC Lic_] = 1 then 'DEEC'
end as abcd
from [Sales Invoice Header] SIH ,[Customer] C, [Country_Region] CR,
[Sales Invoice Line] SIL,[Item] I where I.No_ = SIL.No_ and SIL.[Document No_]='PEXP1213-110' and SIH.No_ = SIL.[Document No_] and C.No_ = SIH.[Bill-to Customer No_] and C.[Country_Region Code] = CR.Code group by I.[Old Product Code], I.[Trade Name], I.[Short Name], SIH.[Sell-to Customer Name],SIH.[Sell-to City],SIH.[Customer Marks - 1],SIL.[Dimension Group Code],I.[Group Description], SIH.[Country of Origin of Goods], SIH.[Ship-to Name],SIH.[Ship-to Address], SIH.[Ship-to Address 2] , SIH.[Ship-to City], SIH.[Ship-to Post Code],SIH.[Bill-to Name],SIH.[Bill-to Address],SIH.[Bill-to Address 2],SIH.[Bill-to City] , SIH.[Bill-to Post Code],SIH.[Total Boxes],C.Contact ,CR.Name,I.[Base Box UOM], I.[EPCG License],I.[DEEC Lic_]

You need to solve it programmatically like
if cstr(rs("Old Product Code"))="[]" then
response.write("")
else
response.write(rs("Old Product Code"))
end if

Related

Combining rows on a query in access 2010

First off I know nothing about VB and the post I have seen on here refer to that, I am sure that this is a very simple thing to do so please help
I am trying to hve my TN Route be my primary key/no duplicates and have date driver 1 driver 2 and driver 3 all in diff cells and all side by side, and even though the tbl that it is pulling from the TN route is primary, it keeps adding additional rows for each driver.
See attached screenshot:
Thank you in advance.
Stan
data sheet view of query
This query will do it for you. Again, it's not preferable because in Access SQL tends to be a little messy on account of it not having features that more robust SQL platforms do - but it will work. You'll need to change the name of your Date column to Route Date in order for this to work, and replace my tblTest with whatever your table name is:
SELECT DISTINCT tblTest.[TN Route], tblTest.[Route Date], tA.[Driver 1], tB.[Driver 2], tC.[Driver 3]
FROM ((tblTest LEFT JOIN (SELECT tblTest.[TN Route], tblTest.[Route Date], [Driver 1] FROM tblTest WHERE [Driver 1] <> '') AS tA ON (tblTest.[Route Date] = tA.[Route Date]) AND (tblTest.[TN Route] = tA.[TN Route]))
LEFT JOIN (SELECT tblTest.[TN Route], tblTest.[Route Date], [Driver 2] FROM tblTest WHERE [Driver 2] <> '') AS tB ON (tblTest.[Route Date] = tB.[Route Date]) AND (tblTest.[TN Route] = tB.[TN Route]))
LEFT JOIN (SELECT tblTest.[TN Route], tblTest.[Route Date], [Driver 3] FROM tblTest WHERE [Driver 3] <> '') AS tC ON (tblTest.[Route Date] = tC.[Route Date]) AND (tblTest.[TN Route] = tC.[TN Route])
In Access 2010, go Create > Query Design > add your table, and then paste the SQL into the SQL view of the query designer. You can even make a standalone table out of the result.

Microsoft Access Error

Error: Invalid use of IS operator in query expression...
Here is the formatted SQL-Code by poorsql.com
TRANSFORM Sum(Jacksonville.[Lease Rent]) AS SumOfAmount
SELECT S.Unit
,S.[Floorplan]
,S.[Unit Designation]
,S.SQFT
,S.[Unit and Lease Status]
,S.NAME
,S.[Move-In and Move-Out]
,S.[Lease Start]
,S.[Lease End]
,S.[Market and Addl.]
,S.[Sub Journal]
,S.[Trans Code]
,S.[Lease Rent]
,S.[Charges and Credits]
FROM Jacksonville
,(
SELECT Q.Id
,Val(DMax(“Id”, ”Jacksonville”, ”Id <= “ & Q.[Id] & “
AND Unit IS NOT Null”)) AS ParentId
FROM Jacksonville AS Q
) AS T
,(
SELECT Jacksonville.Id
,Jacksonville.Unit
,Jacksonville.[Floorplan]
,Jacksonville.[Unit Designation]
,Jacksonville.SQFT
,Jacksonville.[Unit and Lease Status]
,Jacksonville.NAME
,Jacksonville.[MoveIn and MoveOut]
,Jacksonville.[Lease Start]
,Jacksonville.[Lease End]
,Jacksonville.[Market and Addl]
,Jacksonville.[Sub Journal]
,Jacksonville.[Trans Code]
,Jacksonville.[Lease Rent]
,Jacksonville.[Charges and Credits]
FROM Jacksonville
WHERE Jacksonville.Unit IS NOT NULL
) AS S
WHERE Jacksonville.Id = [T].[Id]
AND T.ParentId = [S].[Id]
GROUP BY T.ParentId
,S.Unit
,S.[Floorplan]
,S.[Unit Designation]
,S.SQFT
,S.[Unit and Lease Status]
,S.NAME
,S.[Move-In and Move-Out]
,S.[Lease Start]
,S.[Lease End]
,S.[Market and Addl.]
,S.[Sub Journal]
,S.[Trans Code]
,S.[Lease Rent]
,S.[Charges and Credits]
PIVOT Jacksonville.[Trans Code] IN (
[“ADMIN HOUS”]
,”EXRENT”
,[”LHA RENT”]
,[”MK-PREMIUM LHA”]
,”RENT”
,”SUBRENT”
,”SUBSIDY”
,”UTAC”
,”UTILREIMB”
,”OFF / SOCIAL”
);
This syntax works on my other one, but not here for some reason. Why is my IS statement wrong?
Not sure how to edit the query structure on here.
Replace the "smart quotes" (from a copy-paste from Word?) with double-quotes:
,Val(DMax("Id", "Jacksonville", "Id <= " & Q.[Id] & "
AND Unit IS NOT Null")) AS ParentId

How do I display certain text for blank results in a column. MYSQL

I'm needing to display the words "None provided" for any customers that did not give a second address. What would I use to only provide the address2 column with those words where the return is blank?
/* Create a customer list that shows the customer name, address, second address (if the customer does not list a second address, print out "none provided")
and postal code. */
SELECT CONCAT(first_name," ",last_name) AS Name,
CONCAT(address.address,",",address.address2,",",postal_code) AS Customer_info
FROM customer
INNER JOIN address
ON customer.address_id = address.address_id;
Use the IF() function
CONCAT(address.address, ',', IF(address.address2 != '', address.address2, 'None provided'), ",", postal_code) AS Customer_info
You can use case to solve your problem.
SELECT CONCAT(first_name," ",last_name) AS Name,
CASE
when address = '' OR andress IS NULL then
"None provided"
when address <> ''then
CONCAT(address.address,",",address.address2,",",postal_code)
END AS Customer_info
FROM customer
INNER JOIN address
ON customer.address_id = address.address_id;

SQL Subquery issue 3

I have a issue with my SQL code.
When I run this code I'm getting such error mesage:
**
Subquery returned more than 1 value. This is not permitted when the
subquery follows =, !=, <, <= , >, >= or when the subquery is used as
an expression.
**
I don't know how to correct this code to run it?
Can somebothy look at it and help me with it?
Thank you for your help,
SELECT dbo.FRA$.[GUID], dbo.FRA$.[Last Name],
dbo.FRA$.[First Name], dbo.FRA$.[HR Manager Last Name],
dbo.FRA$.[HR Manager First Name], (SELECT dbo.FRA$.[Business Email Address] FROM dbo.FRA$ t WHERE t.[HR Manager ID] = t.[Emplid]) AS [HR Manager E-Mail],
dbo.LOC.Descr AS [COMPANY NAME], dbo.FRA$.[Location Code],
dbo.LOC.[ADDRESS], dbo.LOC.Postal, dbo.LOC.City, dbo.FRA$.[National ID], dbo.FRA$.[Current Employee Class Desc] AS [Current Empl Class],
dbo.FRA$.[Contract type description] AS [CONTRACT TYPE], dbo.FRA$.[Business Title],
CASE dbo.FRA$.[Current Employee Class Desc]
WHEN 'Operator' THEN 10
WHEN 'Clerical worker' THEN 22
WHEN 'Technician' THEN 32
WHEN 'Supervisor' THEN 33
WHEN 'Manager&Engineer' THEN 54
END AS [Salary brutto],
FORMAT(dbo.FRA$.[Birthdate],'yyyy-MM-dd') AS [Birth Date], FORMAT(dbo.FRA$.[Last Start Date],'yyyy-MM-dd') AS [Hire Date]
FROM dbo.FRA$
INNER JOIN dbo.LOC
ON dbo.FRA$.[Location Code] = dbo.LOC.[Location]
WHERE [HR Status] IN ('International Assignment','Active','Leave of Absence');
Try to replace
SELECT dbo.FRA$.[Business Email Address] FROM dbo.FRA$ t WHERE t.[HR Manager ID] = t.[Emplid]
with
SELECT TOP 1 t.[Business Email Address] FROM dbo.FRA$ t WHERE [HR Manager ID] = t.[Emplid]
it will take only one row from rows returned by your subquery

Grouping by same column / variable using two separate imported views and separate calculations

So basically my code involves a created a table which has the LAST COLUMN as the SUM of the previous two columns, with the first of the two coming from table X and the second of the two columns coming from the 'INNER JOIN OF table X with table Y'.
HOWEVER, I want to group ALL THREE of these columns by the 'COUNTERPARTY', a variable which is present BOTH in 'table X' AND in 'INNER JOIN OF TABLE X WITH TABLE Y.'
The tricky part is that there will be some COUNTERPARTIES for which we have data set 1 (coming from TABLE X) and some COUNTERPARTIES for which we have data set 2 (coming from INNER JOIN OF table X with table Y) and SOME FOR WHICH WE HAVE BOTH DATASETS! I WANT TO INCLUDE THE INTERSECTION AS WELL AS THE OUTLIERS BUT ONLY AFTER CHECKED AGAINST A MASTER KEY OF COUNTERPARTIES called c.COUNTERPTY.
Please carefully go through the code below to see how the above explanation is relevant to the problem at hand. I apologize for the length of the code.
select
p.Name as ENTITY, t.[Counterparty Code], c.CNTRPTY_DS as COUNTERPARTY, cs.Tier,
... irrelevant code removed
sum((t.[Current value decimal] - t.[Trade price decimal])/100 * case when t.[Buy Sell Code] = 'B'
then 1 else -1 end * t.[Open Amount]) as [OPEN MTM ($)],
sum((t2.[Weighted Average Settled Pair Off Price] - t2.[Trade price decimal])/100 * case when t2.[Buy Sell Code] = 'B'
then 1 else -1 end * ISNULL(PO.[Pairoff Amount],0)) as [Unsettled Pairoffs/ AOTs ($)],
sum((t.[Current value decimal] - t.[Trade price decimal])/100 * case when t.[Buy Sell Code] = 'B'
then 1 else -1 end * t.[Open Amount]) + sum((t2.[Weighted Average Settled Pair Off Price] - t2.[Trade price decimal])/100 * case when t2.[Buy Sell Code] = 'B'
then 1 else -1 end * ISNULL(PO.[Pairoff Amount],0)) as [TOTAL MTM Exposure ($)]
from
[la-w08-qrm-db-1].qrmprod.dbo.vw_QRM_Trades t2
inner join
[la-w08-qrm-db-1].qrmprod.dbo.VW_QRM_TRADE_PAIROFFS PO
ON
PO.[In Ticket Number] = t2.[Ticket number]
and PO.[Portfolio ID] = t2.[Portfolio ID]
and t2.[derivative type] = 'F' -- note repeat below
and t2.[forward type] ='MBS'
and t2.[Counterparty Code] not in ('PLS', 'PNCO')
and t2.[Portfolio ID] in (1,7)
and t2.[Settlement date] > GETDATE(),
prod.dbo.vw_QRM_Trades t,
prod.dbo.portdesc p,
prod.dbo.cptyall c,
prod.dbo.VW_MB_ACTIVE_RUN r,
pulsar.dbo.CntrPrtySetup CS,
pulsar.dbo.CntrPrtyTiers CT
where
r.mrktid = 1
And r.asmpid = 1
And r.cyclid = 1
and r.compid = t.[Company ID]
and r.portid = t.[Portfolio ID]
and p.PORTID = t.[Portfolio ID]
and c.COUNTERPTY = t.[Counterparty Code] --key piece of code
and cs.CNTRPTY_NO = c.CNTRPTY_NO
and cs.PortID = t.[Portfolio ID]
and cs.Tier = ct.Tier
and t.[derivative type] = 'F' -- note repeat above
and t.[forward type] ='MBS'
and t.[Counterparty Code] not in ('PLS', 'PNCO')
and t.[Portfolio ID] in (1,7)
and t.[Open Amount] > 0
group by
p.Name, c.CNTRPTY_DS , t.[Counterparty Code], cs.Tier -- yes this
order by
p.Name, c.CNTRPTY_DS , t.[Counterparty Code], cs.Tier -- and this
The way to do is was to actually use UNION in order to join three tables together in the order and given the properties I wanted from each of them. Eventually I did manage to finish the whole stored procedure!