OleDbDataReader not giving same results as SQL Developer - sql

The following query on my oracle db gives results that look fine when run in SQL Developer.
select *
from guideline$ a left outer join textfragment$ t
on (a.TEXTFRAGMENT_CODE = t.TEXTFRAGMENT$_CODE)
start with a.knowledge$_Code = 71122 and a.guideline$_pcode is null
connect by prior a.guideline$_Code = a.guideline$_pcode
order SIBLINGS by a.tag_order
All rows are populated correctly. When the same exact query is ran in my program using OleDbReader.ExecuteReader() some of the rows contain a null value for a specific column when they didn't in my SQL Developer results. The data type of that column is CLOB. I can not see any pattern as to why some of the rows have a null value and some do not.
Not sure what other information would be helpful...
Does anyone have any ideas on what might be going on?

Your problem may be related to the way that binary data is retrieved with OleDbDataReader.
You should use GetBytes(), and follow this article.

Related

Postgres SQL column aliasing based on a query

I am trying to find a way to do SQL column aliasing based on a query. I'm well aware that the SQL below is not valid, it's just provided as an example of what I wish did worked. Can anyone think of a way of doing this?
select col_001_name AS (select col_001_name FROM public.intparms WHERE base_tbl_name = '130')
FROM public.intparms WHERE base_tbl_name = '130';

Sql loop through the values on a table

first off, noob alert! :))
I need to construct a query that runs on many tables. The tables vary on name just on the last digits as per client code. The thing is, the values that change aren't sequential so looping as in i=1,2,3,... does not work. A possible solution would be to have those values on a given field on an other table.
Here is the code for the first two clients 015 and 061. The leading zero(s) must are essential.
SELECT LnMov2017015.CConta, RsMov2017015.DR, RsMov2017015.NInt, "015" AS CodCli
FROM LnMov2017015 INNER JOIN RsMov2017015 ON LnMov2017015.NReg = RsMov2017015.NReg
WHERE (((LnMov2017015.CConta)="6" And (LnMov2017015.CConta)="7") AND ((RsMov2017015.DR)=9999))
UNION SELECT LnMov2017061.CConta, RsMov2017061.DR, RsMov2017061.NInt, "061" AS CodCli
FROM LnMov2017061 INNER JOIN RsMov2017061 ON LnMov2017061.NReg = RsMov2017061.NReg
WHERE (((LnMov2017061.CConta)="6" And (LnMov2017061.CConta)="7") AND ((RsMov2017061.DR)=9999))
...
So for the first SELECT the table Name is LnMov2017015, the ending 015 being the value, the client code, that changes from table to table e.g. in the second SELECT the table name is LnMov2017061 (061) being what distinguishes the table.
For each client code there are two tables e.g. LnMov2017015 and RsMov2017015 (LnMov2017061 and RsMov2017061 for the second set client shown).
Is there a way that I can build the SQL, based upon the example SQL above?
Does anyone have an idea for a solution? :)
Apparently it is possible to build a query object to read data in another db without establishing table link. Just tested and to my surprise it works. Example:
SELECT * FROM [SoilsAgg] IN "C:\Users\Owner\June\DOT\Lab\Editing\ConstructionData.accdb";
I was already using this structure in VBA to execute DELETE and UPDATE action statements.
Solution found :)
Thank you all for your input.
Instead of linking 100 tables (password protected), I'll access them with SLQ
FROM Table2 IN '' ';database=C:\db\db2.mdb;PWD=mypwd'
And merge them all with a query, before any other thing!

display passed parameter in an ssrs report even if there are no associated records in the database

I need to create an SSRS report that is passed a list of parameters and return all the parameters, even if there are no records associated with the parameter. I have posted below of what I am trying to accomplish.
Passed parameters: 12388501, 1238853, 1238858, 123885900, 12388573
And would like the final report to look like the example below:
The parameters passed in this example are Account Numbers. How can I get the Account Number to display as a record even though it is not contained in the database?
I am using SQL Server 2012 database, SSMS for development of the query and will ultimately create the report in SSRS.
I hope my wording of this question makes sense. If there is anything missing in my query please let me know and I will provide it. Thanks in advance!
Step 1: Split your string into rows of a table. My understanding is that Erland Sommarskog is regarded as an authority on handling lists in SQL Server: Arrays and Lists in SQL Server 2008
Using Table-Valued Parameters (revised in 2012. He has a page devoted to the broader topic/earlier SQL Server versions at Arrays and Lists in SQL Server.) There are other methods for splitting strings into table-valued parameters via user-defined functions, etc. that may perform reasonably well for small lists similar to what you have here.
Step 2: using that table-valued parameter that you've populated from the splitting of the string parameter, form your query like the one below. The INNER JOIN in the first SELECT will give you only those records that match an AccountNumber in your inline table and the LEFT OUTER JOIN with the WHERE clause in the second SELECT will give you only AccountNumber values that don't exist in myTable. You can substitute other values for the NULL values I've stubbed in as long as they match the data types of the corresponding fields in myTable.
SELECT mt.AccountNumber,mt.LastName,mt.FirstName,mt.ContactNumber,mt.Address,mt.City,mt.State,mt.Zip
FROM myTable mt JOIN #t t ON mt.AccountNumber = t.AccountNumber
UNION
SELECT t.AccountNumber,NULL LastName,NULL FirstName,NULL ContactNumber,NULL Address,NULL City,NULL State, NULL Zip
FROM #t t
LEFT OUTER JOIN myTable mt ON t.AccountNumber = mt.AccountNumber
WHERE mt.AccountNumber IS NULL

SQL Joins Not Returning All Field Values; Different Field Values Returned When Order Changed

I'm using the following SQL to query 3 simple tables and pull back results. When I run this query in SQL Server 2005 EM (database that's being used), the correct recordset results are returned. When I execute this from my webpage (ASP) via an SQL statement or a stored procedure, I get blank values for some of the columns. Also, I noticed that when I change the order of the tables being selected in my FROM clause, some of the previous columns then return blank values. Is there something wrong with my SQL for it not to work when calling it? I developed my app locally and it works fine. When I deployed it to the client's network, the problems started... The client is running Win 2000 SP4 as their application server and my app is developed in ASP 3.0 with a SQL Server 2005 datastore.
SELECT
Scorecard_Measure.Measure,
Scorecard_Measure.Target,
Scorecard_Measure.YTD,
Scorecard_Measure.Status,
Scorecard_Measure.Explanation,
Scorecard_Measure.Division,
Scorecard_Measure.ZIndex,
Scorecard_Measure.LastUpdated,
Scorecard_Measure.ID,
Scorecard_Objectives.Details,
Scorecard_Objectives.ZIndex,
Scorecard_ObjectiveCats.IdentityLetter
FROM
[Scorecard_Measure],
[Scorecard_Objectives],
[Scorecard_ObjectiveCats]
WHERE
Scorecard_Measure.ObjID=Scorecard_Objectives.ID
AND Scorecard_Objectives.ObjCatID = Scorecard_ObjectiveCats.ID
AND Scorecard_Measure.FiscalYear = '2011'
AND Scorecard_Measure.Publish='Y'
ORDER BY Scorecard_Measure.LastUpdated DESC
Scorecard_Objectives.ID is a foreign key in the Scorecard_Measure table, Scorecard_ObjectiveCats.ID is a foreign key in the Scorecard_Objectives table.
Also, a weird occurence. I have two column names that are the same and when I reference those columns, the server isn't throwing an error like I've seen before saying "your results have columns with the same name, reference them using the tables they come from"... e.g. rs("Scorecard_Objectives.ZIndex") and rs("Scorecard_Measure.ZIndex") -- when I use these references, I get an error from IIS.
Any points is appreciated. Thanks in advance!
Access Both ZINDEX with different variables. Try this join query.
SELECT
Scorecard_Measure.Measure,
Scorecard_Measure.Target,
Scorecard_Measure.YTD,
Scorecard_Measure.Status,
Scorecard_Measure.Explanation,
Scorecard_Measure.Division,
Scorecard_Measure.ZIndex as MZIndex,
Scorecard_Measure.LastUpdated,
Scorecard_Measure.ID,
Scorecard_Objectives.Details,
Scorecard_Objectives.ZIndex as OZIndex,
Scorecard_ObjectiveCats.IdentityLetter
FROM
Scorecard_Measure INNER JOIN Scorecard_Objectives
ON Scorecard_Measure.ObjID=Scorecard_Objectives.ID
AND Scorecard_Measure.FiscalYear = '2011'
AND Scorecard_Measure.Publish='Y'
INNER JOIN Scorecard_ObjectiveCats
ON Scorecard_Objectives.ObjCatID = Scorecard_ObjectiveCats.ID
ORDER BY Scorecard_Measure.LastUpdated DESC

Recordset returns the correct number of row but with all field empty

I have the same copy of access running in 3 cities right now. They work perfectly ok. They are 99% the same with one minor difference. Each of them has two views which use different odbc connection to different cities DB (all these databases are SQL Server 2005). The views act as datasource for some two very simple queries.
However, while I tried to make a new copy for a new city, I found that one of the simple internal query returns the correct number of row but all data are empty while the other query functions correctly.
I checked the data of these two views, the data is correct.
The one causing problem are like
Select * from View_Top where Name = "ABC"
when the recordset returns, even rs!Name give me an empty string.
Please help
Well the query looks a little wrong to me, try using ' instead of " to delimit your ABC string...
Without the definition of VIEW_TOP it's hard to tell where your error is, but if you're getting rows but the columns are NULL I'm guessing that VIEW_TOP (or something it depends on) includes an OUTER JOIN and you're pulling the columns from the wrong side of the JOIN.
SELECT
acc.FIRM,
acc.OFFICE,
acc.ACCOUNT,
a.CONV_CODE,
a.OTHER_AMT AS AMOUNT,
a.TRANS_DATE,
a.DESCRIPTN,
a.JRNAL_TYPE
FROM AccTrans AS a LEFT OUTER JOIN ACC AS acc ON a.ACCNT_CODE = acc.ACCNT_CODE
WHERE
(acc.SUN_DB = 'IF1') AND
(ANAL_T0 <> '') AND
(a.TRANS_DATE < '20091022') AND
(a.JRNAL_TYPE = 'MATCH');
This is the definition of the view. Indeed, in Access i am able to view the result of this query, it has data. that's why i know the recordset returns the correct number of row (by counting the loop in the code). sorry for my mistakes, i use Account in the where clause, the select statements should be like
select Firm, Office, Account, Trans_Date.... from
view_top
where account = 'ABC'
the query returns the right number of row but all row data (even the account field) are empty string.
then i found out what really cause the problem is the AMOUNT field, if i omit the amount, everything works. though i don't understand why.
view_top definition
"Name, Account, AccountCode, Amount, Date...."
Select Statements:
Select Name, Account, AccountCode, Amount, Date
From View_Top Where Name = 'xxx'
I found that if I omit the Amount, everything works.
Though I still don't understand why.