Solved

query conversion T-SQL -> Jet

Posted on 2013-01-08
8
516 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

739 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