Solved

query conversion T-SQL -> Jet

Posted on 2013-01-08
8
519 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

691 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