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?
#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

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  how to get some values from js on python console by python code vivekagrey 1 90 Feb-13-2020, 09:26 PM
Last Post: micseydel
  code not writing to projNameVal portion of code. umkc1 1 84 Feb-05-2020, 10:05 PM
Last Post: Larz60+
  Converting query string as a condition for filter data. shah_entrance 1 79 Jan-14-2020, 09:22 AM
Last Post: perfringo
  C code to python jhapradeep88 7 262 Jan-09-2020, 06:14 AM
Last Post: jhapradeep88
  Error in python code 'import callbot' Lou_Reed 3 186 Jan-07-2020, 09:33 PM
Last Post: Clunk_Head
  I don't know what's wrong with this code [Python Console] H0M1C1D4L_P1G 6 203 Dec-22-2019, 10:27 PM
Last Post: snippsat
  How to execute Python code leemao 2 133 Dec-21-2019, 02:35 PM
Last Post: leemao
  what does code mean (python) sveto4ka 0 225 Nov-30-2019, 02:05 PM
Last Post: sveto4ka
  want same code in python deepakkr3110 1 267 Nov-22-2019, 06:46 AM
Last Post: buran
  What was my mistake in this Python code (easy)? voltman 4 196 Nov-19-2019, 09:58 PM
Last Post: snippsat

Forum Jump:


Users browsing this thread: 1 Guest(s)