Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Converting SQL Code To Python Code Query
#1
Hi there,

Is there any Python Utility available on the Internet, that can convert SQL Code, to Python Code ?

Here is the SQL Code, I would like converting to Python Code :-

SELECT * INTO #Temp4
FROM
(
SELECT
tt5.[Venue],
tt5.[BID],
MIN(tt1.[Date]) AS [Date],
tt5.[Display / Flypast],
SUM(tt1.[Duration]) AS [Duration (mins)],
(SELECT DISTINCT '; ' + t5.[Aircraft Combined]
	FROM #Temp5 t5
	WHERE tt5.[Venue] = t5.[Venue]
	AND tt5.[BID] = t5.[BID]
	AND tt5.[Display / Flypast] = t5.[Display / Flypast]
	FOR XML PATH ('')) [Aircraft Combined],
SUM(tt5.[Dakota and Fighters in Same Slot?]) AS [Dakota and Fighters in Same Slot?]
Any info and help would be appreciated

Regards

Eddie Winch
#2
You can use sqlalchemy I just wrote a simple SqlAlchemy tutorial (last week)
It makes SQL easy
tutorial: https://python-forum.io/Thread-SqlAlchem...-Data-Load
KipCarter likes this post
#3
Many thanks for your information Larz60+, it's much appreciated. I can't work exactly, how to do a conversion with SQLAlchemy ? To get a resulting Output, in Python Code equivalent ?

I mean what would I have to type, in the Python, in my case 3.7 Shell ?

I have looked at some documentation, but I am not completely sure, of what to do.

I mean, doing the usual thing of importing, in this case SQLAlchemy, what else would I have to type, i.e. using the SQL Code, I provide in this Thread ?

Sorry about my lack of understanding.

Regards

Eddie Winch
#4
well in python, you would:
  • Open a database link
  • create a cursor
  • create a string containing the query (using proper security measures, so as to avoid sql injection)
  • execute the string within the cursor
  • commit your changes
  • close the database link.
  • Learn how to do all of above, suggest: https://www.python-course.eu/sql_python.php
Alternative: Learn SqlAlchemy
#5
Thanks for that info Larz60+, I see you can't simply, have SQL code translated into Python Code, using SQLAlchemy ?

Code has to be executed, as part of querying a database etc. Because at the moment, I only want, direct translation of that SQL Code, to Python Code.

Eddie
#6
Quote: I see you can't simply, have SQL code translated into Python Code, using SQLAlchemy?

You need to define a model (which is a class the defines the table columns, indexes, etc.), quite simple, see tutorial
then to access code, create an SqlAlchemy session and run the query.
The model should also include common database methods that you would create, for example queries which you use over and over
as you class grows, your database can become more and more of a black box.

the tutorial will take you less time than you've already spent on this thread.
#7
Hi Larz60+,

I simply wan't the SQL Code, I provide in this Thread, converted to Python Code.

Are there any Converters, i.e. SQL Code to Python/Pandas Code Utilities on the Internet ?

If you mean in your replies, that I can do that with, the SQLAlchemy Utility.

Could you tell me exactly, what I should type to achieve that ?

Sorry I am confused, about what I should type, even with the Tutorial you provide ?

Can you help me, if that is okay ?

Regards

Eddie Winch
#8
You can use ORM like SQLAlchemy as suggested by Larz, but you can also use directly the SQL query. There are different packages/drivers to ork with different databases. What DB do you work on?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

#9
Hi buran,

I am using the following Excel File :-

http://web.archive.org/web/2009080507022...6AA506.xls

My sister is writing a Code, for me in SQL Code, to filter the Data, as I would like, it to be displayed.

I asked questions how to finish the Code, in following Thread, but nobody has replied to my latest Posts on Page 3, of that Thread unfortunately, for a Python Pandas Code I have. So I would like a conversion of that SQL Code, to Python/Pandas Code, I provide in this Thread, to help me solve the issues myself, here is the Thread Link, I am refering to :-

https://python-forum.io/Thread-Filtering...cal-Values

Regards

Eddie Winch
#10
if you are not getting the desired response, obviously there is something unclear about your request - either it lack information or is too broad. In any case what you try to do here is example of XY problem and won't help - you ask something, that is not your actual problem.
The best approach would be to keep the discussion in the original thread.
ndc85430 likes this post
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs


Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Compiling Python 3.8.5 source code results in build error Deepan 0 85 Sep-14-2020, 04:11 AM
Last Post: Deepan
  [split] Python code help sairam17519 3 183 Sep-10-2020, 01:44 PM
Last Post: sairam17519
  Python code help aed71 6 220 Sep-09-2020, 08:22 PM
Last Post: aed71
  New in Python. Have question on my code. ztx19981023 2 142 Sep-02-2020, 03:34 AM
Last Post: Larz60+
  Translation of R Code to Python for Statistical Learning Course SterlingAesir 2 102 Aug-27-2020, 08:46 AM
Last Post: ndc85430
  Syntax error in python code sample ErnestTBass 5 330 Aug-14-2020, 07:14 PM
Last Post: deanhystad
  Python code for exporting table using Selenium gj31980 4 320 Aug-04-2020, 01:29 AM
Last Post: gj31980
  How to convert a python code to binary? rsurathu 0 146 Aug-02-2020, 08:09 AM
Last Post: rsurathu
  How to do it in simplified Python code Jacks 0 156 Jul-14-2020, 04:21 PM
Last Post: Jacks
  Need Outlook send email code using python srikanthpython 2 427 Jul-01-2020, 03:15 AM
Last Post: srikanthpython

Forum Jump:


Users browsing this thread: 1 Guest(s)