SQL looking for a part number ending in '~0000' - sql

I am trying to find records ending in ~0000 such as ABC~0000
but everything I try doesn't seem to work. Some examples:
and left (mfr_part_number, 4) = 'ABC~' -- finds nothing
and left (mfr_part_number, 3) = 'ABC' -- finds stuff
AND RIGHT(MFR_PART_NUMBER, 4) = '0000' -- finds nothing
AND RIGHT(MFR_PART_NUMBER, 5) = '~0000' -- finds nothing
and DbFunctions.Like(MFR_PART_NUMBER,'%0000') -- suggested elsewhere, but not recognized in MSSMS.
I am using:
SQL Server Management Studio 15.0.18206.0
Microsoft Analysis Services Client Tools 15.0.1567.0
Microsoft Data Access Components (MDAC) 10.0.18362.1
Microsoft MSXML 3.0 6.0
Microsoft .NET Framework 4.0.30319.42000
Operating System 10.0.18363
Thanks!

Are you using all of those AND statements in your WHERE clause? If so, that would cause nothing to return if there's no data that matches all criteria.
Try
SELECT column1, column2...
FROM yourdb
WHERE MFR_PART_NUMBER LIKE '%0000'

Related

VS 2019 Db Project - Cant use ChangeTable

I'm having a bit of trouble using change tracking in a vs 2019 db project.
I have referenced master in my db project and have ensured the function actually runs, However I cannot build my db project as I keep getting this build error.
the reference is ambiguous because it could refer to any of the following objects: [CT].[SYS_CHANGE_VERSION], [CT].[TrackedChanges]::[SYS_CHANGE_VERSION] or [dbo].[History_table].[TrackedChanges]::[SYS_CHANGE_VERSION].
Here is my sql
SELECT
TrackedChanges.SYS_CHANGE_VERSION,
TrackedChanges.Change_ID,
HT.Record_ID,
HT.Field_Name,
HT.Changed_By_User_ID,
HT.New_Value,
HT.Table_Name,
HT.Control_ID,
HT.Change_DateTime
FROM
dbo.History_table AS HT
RIGHT OUTER JOIN
CHANGETABLE(CHANGES dbo.History_table, 0) AS TrackedChanges
ON HT.Change_ID = TrackedChanges.Change_ID
WHERE
Control_ID is not null
AND Control_ID <> 0
Any help is greatly appreciated.
Ok so after searching stack overflow for 'error sql71501' a user suggested doing a schema compare from the db to see if anything was missing. After such I noticed my table was missing
'ALTER TABLE [dbo].[History_Table] ENABLE CHANGE_TRACKING WITH (TRACK_COLUMNS_UPDATED = OFF);'
And it now builds :)

Omitting the creation of a temporary access path with DB2/400 when accessing DDS-defined tables with SQL

I have two table definitions in DDS, compiled into *FILE objects and filled with data:
Kunpf:
A UNIQUE
A R KUNTBL
A FIRMA 60A ALWNULL
A KUNR 5S 0B
A KUNID 4S 0B
A K KUNR
A K KUNID
Kunsupf:
A R KUNSUTBL
A KUNID R B REFFLD(KUNID KUN/KUNPF)
A
A SUCHSTR 78A
A K SUCHSTR
A K KUNID
I'm using the following statement in interactive SQL (STRSQL):
SELECT DISTINCT FIRMA, KUNR FROM KUN/KUNPF
LEFT JOIN KUN/KUNSUPF ON (KUNPF.KUNID = KUNSUPF.KUNID)
WHERE SUCHSTR LIKE 'Freiburg%'
ORDER BY FIRMA
FOR READ ONLY
Everytime I execute this statement, I'm getting a considerable delay until the answer screen opens up. Beforehand a message is shown, stating that a temporary access path is being created.
How can I find out which/how this temporary access path is created? My goal is to have this access path made permanent so it doesn't need to be rebuilt with every invocation of this query.
I searched the net (especially the IBM site) but what I found out was mostly for DB2 on z/OS. The F4-Prompting facility in STRSQL doesn't provide help: I was searching for something like EXPLAIN SELECT from MySQL. The IBM DB2 Advanced Functions and Administration PDF states that there's a debug mode but it seems that it is only available from some (old) Windows tool I don't remember to have.
I'm utilizing V4R5, if this is relevant.
to see the access path on the green screen...
strdbg
strsql
run your statement
exit f3
enddbg
dspjoblog
the access path messages are at the bottom of the log f10 f18 afaik
v4r5??? That's like 20 years old...
For the IBM i, the "Run SQL Scripts" component of the old Client Access For Windows iSeries Navigator component and the new Access Client Solutions (ACS) contains Visual Explain (VE).
Luckily it seems though it was added to v4r5
http://ibmsystemsmag.com/ibmi/administrator/db2/database-performance-tuning-with-visual-explain/
Just start iNav, right click on "Database" and select "Run SQL Scripts"
Paste your query there and click "Visual Explain" -->"Run and Explain"
(or the corresponding button)
Optionally, in green screen.
Do a STRDBG to enter debug mode, F12 to continue and then go into STRSQL. The Db optimizer will then output additional messages into the joblog giving you more information about what it is doing..

Existing LINQ to Entities queries throw exception on upgrade to VS 2017

We recently upgraded our visual studio from 2013 to 2017, are working on with EntityFramework 6.1.3, and with the upgrade have our projects targetting the 4.7 .NET Framework. With these changes we have existing LINQ queries that are breaking on us.
A simplified example:
Dim comm = Communication.Where(Function (t) t.Id = 1).ToList()
Dim query = (From cc In comm
Let a = ""
Select New With {
.UserName = (From e In Employee
Where e.Initials = cc.EmployeeInitials
Select ee.UserName).FirstOrDefault()
}
)
In this situation the result will be a System.NotSupportedException with the message being:
LINQ to Entities does not recognize the method 'Company.Core.Models.Communication get_cc()'
Now removing the Let statement from the query fixes the exception and the query will run fine, however I cannot determine why the Let causes problems and more specifically why this query only recently broke.
So I am hoping someone can give a explanation of why this exception cropped up in VS 2017 when it had worked fine in VS 2013 and in our production system for years.

How to debug an intemittent error using Progress OpenEdge database

I have a program that fails intermittently in a complex query.
The error reads:
System.Data.SqlClient.SqlException: Cannot fetch a row from OLE DB provider "MSDASQL" for linked server "LinkedServer".
The query looks like this:
SELECT Replace([JOB-NO],'M0','') as KeyTaskID,
dbo.SFGET_UniqueTaskID([CLIENT-CODE],Replace([JOB-NO], 'M0', ''), 0, [TRADE-CODE]) AS HMSUniqueTaskID,
[LATEST-PRIORITY] AS PriorityCode,
[KeyProperty] AS KeyProperty,
Replace([JOB-NO],'M0','') AS KeyJob,
[JOB-TYPE] as TaskSubType,
CONVERT(varchar(6),[MAINT-OFFICER]) AS Officer,
LEFT(FORENAME + ' ' + SURNAME, 50) AS OfficerName,
[JOB-NO] + ' ' + LEFT(RTRIM(REPLACE([TEXT-LINE], ';', CHAR(13))), 480) AS Description,
dbo.SFGET_FormattedDate([TARGET-DATE],0) AS DueDateTime,
[CURRENT-STAGE-CODE] AS CurrentStageCode
FROM openquery(LinkedServer, '
SELECT DISTINCT
"RM-JOB"."JOB-NO",
"RM-JOB"."CLIENT-CODE",
"RM-JOB"."LATEST-PRIORITY",
"RM-JOB"."TRADE-CODE",
"RM-JOB"."JOB-TYPE",
"RM-JOB"."TARGET-DATE",
"RM-JOB"."MAINT-OFFICER",
"RM-JOB"."TEXT-LINE",
"RM-JOB"."CURRENT-STAGE-CODE",
"RM-JOB"."PLACE-REF",
"IH_OFFICER".FORENAME,
"IH_OFFICER".SURNAME
FROM "PUB"."RM-JOB"
LEFT OUTER JOIN "PUB"."IH_OFFICER"
ON ("IH_OFFICER"."OFFICER-CODE" = "RM-JOB"."MAINT-OFFICER")
WHERE "RM-JOB"."JOB-TYPE" = ''GASS''
AND "RM-JOB"."JOB-STATUS" = 06
AND "RM-JOB"."CONTRACTOR" = ''NWH001'' ') as ibsTasks
INNER JOIN [SVSExtract].[dbo].Property prop
ON ibsTasks.[PLACE-REF] = prop.UserCode
I have been testing it manually using SQL Server Management Studio. It occassionally fails but it mainly works OK.
I am at a loss as to how I can debug an error that I cannot reproduce at will.
Any suggestions?
I'm not that proficient in SqlClients and Progress myself but: the Progress Knowledgebase might give you a solution!
This entry for instance describes a similar error, even if the version mentioned might be older than the one you use? (Always post version when asking about OpenEdge - there's lots of older installations out there and Progress has evolved quite a bit during the last couple of years).
The Knowledgebase is honestly best searched using Google:
Search for instance: site:knowledgebase.progress.com MSDASQL and you'll get 48 results.

Delphi - Either BOF or EOF is True, or the current record has been deleted

This error showed when I tried to select on an empty table in MS SQL Server 2005: "either BOF or EOF is True, or the current record has been deleted". I have used TADOConnection and TADODataSet in Delphi 5 to connect and retrieve data from the database.
Conn := TADOConnection.Create(nil);
DataSet := TADODataSet.Create(nil);
Conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=sa;' +
'Persist Security Info=True;' +
'User ID=user;Initial Catalog=mydb;' +
'Data Source=MYPC\SQLEXPRESS;' +
'Use Procedure for Prepare=1;' +
'Auto Translate=True;Packet Size=4096;' +
'Workstation ID=MYPC;' +
'Use Encryption for Data=False;' +
'Tag with column collation when possible=False';
Conn.LoginPrompt := False;
Conn.Open;
DataSet.Connection := Conn;
DataSet.CommandText := 'SELECT * FROM MYTABLE';
DataSet.Open;
DataSet.Free;
Conn.Free;
Is there a way to check if a database table is empty without incurring such error?
This error originally occured with an update to MDAC_TYP (to 2.6 from memory). According to an old Borland advisory
"This is a bug in the SQL Server provider. Set
CursorLocation = clUseClient to eliminate the error."
There was a ADOExpress patch available from Borland, but the link doesn't work. Embarcadero now host it here: ftp://ftpd.embarcadero.com/pub/delphi/devsupport/updates/adoexpress/d5adoupdate2.exe(Thanks for the official link Jeroen!)
I would recommend downloading and installing all patches listed on the Embarcadero site, assuming you can find them.
Download the ADO update for Delphi 5 here: ftp://ftpd.embarcadero.com/pub/delphi/devsupport/updates/adoexpress/d5adoupdate2.exe
Make sure you also have the regular update installed:
English Enterprise
English Professional
English Standard
There are more updates (Corba, original ADO install) and languages (French, German), but these should get you going.
There also used to be a http://info.borland.com/devsupport/delphi/download_files/zlibupdate.zip, but it is not on the ftpd servers.
--jeroen
It was long time agom but I recall that this problem in Delphi 5 resolves by Delphi update. Early version has serious problems with ADO components
P.S. Also I see that your code uses not typical runtime creation of components and does not use some container like data module or form (not good usually) for visual work with components. Also sometimes useful run simple queries via adoConnection.execute. If you do not use visual components, handling of ADO's Recordset object is much the same as Delphi's AdoDataset.
Since I spent a whole day on this, here is a wrap up of what I did in the end.
Delphi 5 Pro Installation with ADO Express
Uninstall Delphi 5, also deleted installation directory
Install Delphi 5 Pro (I only have a German Delphi Pro edition available)
Install Delphi 5 Pro Update (I used the German update)
Install Delphi 5 ADO Express
Install Delphi 5 ADO Express Update Pack 1
Install Delphi 5 ADO Express Update Pack 2
And the download links (many thanks again Jeroen Wiert Pluimers):
Delphi 5 Pro updates:
ftp://ftpd.embarcadero.com/pub/delphi/devsupport/updates/delphi5/D5ProUpdate.exe
ftp://ftpd.embarcadero.com/pub/delphi/devsupport/updates/delphi5/german/d5proupdate.exe
ADOExpress Update Packs 1 and 2:
ftp://ftpd.embarcadero.com/pub/delphi/devsupport/updates/adoexpress/D5ADOUpgrade.exe
ftp://ftpd.embarcadero.com/pub/delphi/devsupport/updates/adoexpress/d5adoupdate2.exe
And for future reference some screenshots to build the download links (case sensitive):