Solved

query conversion T-SQL -> Jet

Posted on 2013-01-08
8
493 Views
Last Modified: 2013-02-24
Dear Experts

this query works perfectly well in Ms SQL Server:

select *
from cdn.prjstruktura
where exists (select * from cdn.konta
join cdn.dekrety on KKS_GIDNumer = DT_KKSNumer
where (kks_konto like '5%-' + right('0000' + cast(prj_id as varchar), 5) + '-%' or kks_konto like '7%-' + right('0000' + cast(prj_id as varchar), 5)))

However, it doesn't work in Jet (e.g. when I try to execute this statement from Excel VBA or Access).

The problem is in this line:
where (kks_konto like '5%-' + right('0000' + cast(prj_id as varchar), 5) + '-%' or kks_konto like '7%-' + right('0000' + cast(prj_id as varchar), 5)))

Can somebody translate it to Jet SQL please?

thanks
Jarek
0
Comment
Question by:ja-rek
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 38756889
Try this Perhaps:


select *
from cdn.prjstruktura
where exists (select * from cdn.konta
join cdn.dekrety on KKS_GIDNumer = DT_KKSNumer
where (kks_konto like "5*-" + right("0000" + cast(prj_id as varchar), 5) + "*" or kks_konto like "7*-" + right("0000" + cast(prj_id as varchar), 5)))
0
 
LVL 1

Author Comment

by:ja-rek
ID: 38756911
boag2000: unfortunately it doesn't work
0
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 38756993
select *
from cdn.prjstruktura
where exists (select * from cdn.konta
inner join cdn.dekrety on KKS_GIDNumer = DT_KKSNumer
where kks_konto like '5*-' & right('0000' & prj_id, 5) & '-*' or 
kks_konto like '7*-' & right('0000' & prj_id, 5)

Open in new window

0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 38757655
Can you define exactly what "doesn't work" means?

In any event try, it seems like matthewspatrick has your syntax corrected.
0
 
LVL 1

Author Comment

by:ja-rek
ID: 38759064
I have changed also cast to convert to make it work.
0
 
LVL 1

Author Comment

by:ja-rek
ID: 38759076
thanks to all Experts for interest in my question!
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 38759287
I am confused.  Your question was about taking a T-SQL query, and rewriting it for Jet SQL.

What does the CONVERT function have to do with anything?  There is no CONVERT function in Jet.  There are various type conversion functions, such as CStr, CDate, etc., but Jet is perfectly capable of doing an implicit conversion when you concatenate a numeric value with a string.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 38761389
I suspect the author realized after they posted that they were not using JET after all as they are using Pass-Through queries or ADO or something else, but I would not be surprised if we did not hear back from them.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Viewers will learn how the fundamental information of how to create a table.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question