Showing posts with label display. Show all posts
Showing posts with label display. Show all posts

Friday, March 9, 2012

Problem when field is NULL

I am doing a LEFT JOIN, that should display all files in table a even if
there is no match with table B as far as I know.
The problem is that if the field that joins A with B is NULL then I get no
results, I am trying the following:
SELECT a.Id , a.CaseId , a.EmpId, a.AlienId, a.FirmAddressId, b.FirstNm ,
b.MiddleNm, b.LastNm , b.FirmId, c.Processcatalog , a.MainCase ,
d.MaidenNm
FROM Cases a LEFT JOIN Users as d ON a.EmpId = d.UserId
LEFT JOIN Users as b ON ISNULL (a.AlienId,'0') = b.UserId
INNER JOIN Processcatalog as c ON Process = ProcesscatalogID WHERE
ISNULL (a.CaseID,'') LIKE '%MMColParam%' AND ISNULL (b.LastNm,'') LIKE
'MMColParam1%' AND ISNULL (b.FirstNm,'') LIKE 'MMColParam2%' AND
b.Firmid = 'MMColParam3' AND a.archived LIKE 'MMColParam4' and
a.firmaddressid LIKE 'MMColParam5' and ISNULL(a.firmaddressid,'')LIKE
'MMColParam5' AND ISNULL(d.UserID,'') LIKE 'MMColParam6' AND MainCase IS
NOT NULL
ORDER BY a.caseId
---
a = Cases (This is the main table)
b = Contacts (This is the table I am joining to using LEFT join)
Even though I do it like this and I give value = 0 when it is NULL I still
get no matches, and there is at least one results where there is one record
for 'cases' where cases.alienid is NULL, still won't show up.
What am I missing ?
Let me know if you need more info to help, thanks !
AleksOn Fri, 11 Feb 2005 16:00:50 -0500, Aleks wrote:

>I am doing a LEFT JOIN, that should display all files in table a even if
>there is no match with table B as far as I know.
>The problem is that if the field that joins A with B is NULL then I get no
>results, I am trying the following:
>--
>SELECT a.Id , a.CaseId , a.EmpId, a.AlienId, a.FirmAddressId, b.FirstNm ,
>b.MiddleNm, b.LastNm , b.FirmId, c.Processcatalog , a.MainCase ,
>d.MaidenNm
>FROM Cases a LEFT JOIN Users as d ON a.EmpId = d.UserId
>LEFT JOIN Users as b ON ISNULL (a.AlienId,'0') = b.UserId
>INNER JOIN Processcatalog as c ON Process = ProcesscatalogID WHERE
>ISNULL (a.CaseID,'') LIKE '%MMColParam%' AND ISNULL (b.LastNm,'') LIKE
>'MMColParam1%' AND ISNULL (b.FirstNm,'') LIKE 'MMColParam2%' AND
>b.Firmid = 'MMColParam3' AND a.archived LIKE 'MMColParam4' and
>a.firmaddressid LIKE 'MMColParam5' and ISNULL(a.firmaddressid,'')LIKE
>'MMColParam5' AND ISNULL(d.UserID,'') LIKE 'MMColParam6' AND MainCase IS
>NOT NULL
>ORDER BY a.caseId
>---
>a = Cases (This is the main table)
>b = Contacts (This is the table I am joining to using LEFT join)
>Even though I do it like this and I give value = 0 when it is NULL I still
>get no matches, and there is at least one results where there is one record
>for 'cases' where cases.alienid is NULL, still won't show up.
>What am I missing ?
Hi Aleks,
All filtering on the outer-join-ed tables should be move to the ON clause.
To explain: if a row from a (Cases) has no match in b (Users), then the
value of b.FirstNm will be NULL (becuase of the outer join). In the WHERE
clause, you have "... AND ISNULL (b.FirstNm,'') LIKE 'MMColParam2%'", so
these outer-joined rows will fail this test and be removed from the result
set.
You also don't need to use ISNULL here - NULL LIKE 'MMColParam2%' will not
evaluate to true anyway.
Finally, it's better to use = instead of LIKE when searching for one
specific value. Use LIKE only when searching for patterns.
SELECT a.Id, a.CaseId, a.EmpId, a.AlienId, a.FirmAddressId,
b.FirstNm, b.MiddleNm, b.LastNm, b.FirmId,
c.Processcatalog, a.MainCase, d.MaidenNm
FROM Cases AS a
LEFT JOIN Users AS d
ON d.UserId = a.EmpId
AND d.UserID = 'MMColParam6'
LEFT JOIN Users AS b
ON a.AlienId = b.UserId
AND b.LastNm LIKE 'MMColParam1%'
AND b.FirstNm LIKE 'MMColParam2%'
AND b.Firmid = 'MMColParam3'
INNER JOIN Processcatalog AS c
ON ?.Process = ?.ProcesscatalogID -- better qualify ALL columns
WHERE a.CaseID LIKE '%MMColParam%'
AND a.archived = 'MMColParam4'
AND a.firmaddressid = 'MMColParam5'
AND ?.MainCase IS NOT NULL -- better qualify ALL columns
ORDER BY a.caseId
(untested)
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||I am using LIKE because people search for names using the first letters, not
all the name, that gives them flexibility, I use ISNULL because sometimes
they leave the last name of the first name blank, which is NULL in the
database, but I still need to return that record.
"Hugo Kornelis" <hugo@.pe_NO_rFact.in_SPAM_fo> wrote in message
news:bg9q01dk2cr489b62eqtkbq7093gujnv9q@.
4ax.com...
> On Fri, 11 Feb 2005 16:00:50 -0500, Aleks wrote:
>
> Hi Aleks,
> All filtering on the outer-join-ed tables should be move to the ON clause.
> To explain: if a row from a (Cases) has no match in b (Users), then the
> value of b.FirstNm will be NULL (becuase of the outer join). In the WHERE
> clause, you have "... AND ISNULL (b.FirstNm,'') LIKE 'MMColParam2%'", so
> these outer-joined rows will fail this test and be removed from the result
> set.
> You also don't need to use ISNULL here - NULL LIKE 'MMColParam2%' will not
> evaluate to true anyway.
> Finally, it's better to use = instead of LIKE when searching for one
> specific value. Use LIKE only when searching for patterns.
> SELECT a.Id, a.CaseId, a.EmpId, a.AlienId, a.FirmAddressId,
> b.FirstNm, b.MiddleNm, b.LastNm, b.FirmId,
> c.Processcatalog, a.MainCase, d.MaidenNm
> FROM Cases AS a
> LEFT JOIN Users AS d
> ON d.UserId = a.EmpId
> AND d.UserID = 'MMColParam6'
> LEFT JOIN Users AS b
> ON a.AlienId = b.UserId
> AND b.LastNm LIKE 'MMColParam1%'
> AND b.FirstNm LIKE 'MMColParam2%'
> AND b.Firmid = 'MMColParam3'
> INNER JOIN Processcatalog AS c
> ON ?.Process = ?.ProcesscatalogID -- better qualify ALL columns
> WHERE a.CaseID LIKE '%MMColParam%'
> AND a.archived = 'MMColParam4'
> AND a.firmaddressid = 'MMColParam5'
> AND ?.MainCase IS NOT NULL -- better qualify ALL columns
> ORDER BY a.caseId
> (untested)
> Best, Hugo
> --
> (Remove _NO_ and _SPAM_ to get my e-mail address)|||On Fri, 11 Feb 2005 16:51:19 -0500, Aleks wrote:

>I am using LIKE because people search for names using the first letters, no
t
>all the name, that gives them flexibility,
Hi Aleks,
Your code didn't allow for user input. It was just
somecol LIKE 'MMColParam2%' (where LIKE is fine) or
somecol LIKE 'MMColParam4' (where no wildcard is used, so LIKE has no
added value; use = to get better performance)

> I use ISNULL because sometimes
>they leave the last name of the first name blank, which is NULL in the
>database, but I still need to return that record.
But if you use ISNULL (a.AlienId,'0') = b.UserId, you'll only return the
row if b.UserID happens to be equal to '0', which is not too likely to
happen. And if you use ISNULL (b.FirstNm,'') LIKE 'MMColParam2%', you'll
only return the row when '' is LIKE 'MMColParam2%', which will definitely
never be the case, so the row won't be returned.
Q1: Did you try the query I suggested? Did it work?
Q2: Since I now have a feeling that your real problem is quite different
from the simplification you posted, could you now post something a little
bit closer to the real issue? If possible with SQL to construct your
tables and fill them with some sample data, and with a description of the
requested output from that sample data. See www.aspfaq.com/5006.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)

Wednesday, March 7, 2012

Problem Viewing Reports on Server

Hello, we're having a bit of an issue getting Report Server to display reports. We've published via the web-interface and Visual Studio. After we publish, it gives an error and it looks as if it's trying to find the data source that we used to create the report. We've changed the datasource names to match that of the local machine too. Here's the error...

  • An error has occurred during report processing.

  • Cannot create a connection to data source 'LocalDataSourceName'.

  • Keyword not supported: 'driver'.

    Any help would be greatly appreciated. Thank you!

    What is the connection string and which data provider are you using? It looks like the data provider can't handle the connection string.|||Problem solved....we were using an invalid connection string. For some reason it was working on one server but not the other. Just tried a different string on both of them and it works great now.
  • Problem viewing report with Report Viewer

    Hi,

    I am using the Report Viewer Control to display the Reports. My query is generated dynamically so that output the query is a datatable. My application gives the user the flexibility to select the tables & the table-fields on which he wants to run the report. So I cannot have a fixed report file as I do not know what will the user select.

    I tried adding the result datatable as the datasource for the report dynamically.

    protected void RunReport_Click(object sender, EventArgs e){string constg ="server=localhost;Database=techapp;user id=sa;password=admin;";SqlConnection con =new SqlConnection(constg);//query is the query string that is generated at runtimeSqlDataAdapter da =new SqlDataAdapter(query,con);DataSet ds =new DataSet();da.Fill(ds,"ReportDataTable"); con.Close();ViewReport(ds.Tables["ReportDataTable"]);}protected void ViewReport(DataTable dt){ ReportViewer1.ProcessingMode = ProcessingMode.Local; ReportDataSource rd =new ReportDataSource(); rd.Name ="ReportData_Data"; rd.Value = dt; ReportViewer1.LocalReport.DataSources.Add(rd); ReportViewer1.DataBind();}

    My problem is that the entire code gets executed properly without any exception but the report is not displayed. I checked the ReportDataSource & it shows the proper value. In all the samples that I went through, I found that they have mentioned a report file. I don't know if this is the cause of the problem, but if it is then In mycase how can I create a report design file if I wouldn't know what to add in that file at design time.

    I do not have an expertise in this. can anyone please guide me through the right way & let me know what is it that I'm not doing correct?

    I guess its the problem with height of report

    Check whether you have set the height of report as 100%. Change that to some fixed size let say 800px.

    Let me know if you need any further help

    |||

    Hi Ashok,

    I tried adjusting the height of the report viewer . This is the changed code but it still doesn't show any thing.

     ReportViewer1.ProcessingMode = ProcessingMode.Local; ReportViewer1.Height = Unit.Pixel(500); ReportDataSource rd =new ReportDataSource(); rd.Name ="ReportData_Data"; rd.Value = ds.Tables["ReportDataTable"]; ReportViewer1.LocalReport.DataSources.Add(rd); ReportViewer1.DataBind();

    Could the problem be the absence of a report design file ie an rdlc file. I downloaded a sample code from net where the report file is created dynamically & it seemed to work this way.

    Is a report design file by default required for the report viewer control to display the report? What is the complexity involved in creating such design files on your own?? Can you shed some light on these points ?

    Thanks