Solved

query conversion T-SQL -> Jet

Posted on 2013-01-08
8
470 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
 
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
Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now