I have an ongoing issue that I just can’t solve. It concerns a Python script that loads data into a SQL server database. When I run it from my local machine it works fine, however when I run the same script from a server I get the following error: conn = pyodbc.connect(r’Driver={SQL Server};’…
Tag: python
django get record which is latest and other column value
I have a model with some columns, between them there are 2 columns: equipment_id (a CharField) and date_saved (a DateTimeField). I have multiple rows with the same equipment_id and but different date_saved (each time the user saves the record I save the now date time). I want to retrieve the record that has a…
python sqlite3 partial search
I want to do a partial search with python sqlite3. My initial query is: Then I tried using the LIKE keyword and string formatting to obtain partial search results for the title, like this: As in https://stackoverflow.com/a/20904256/13290801 This seems to do the trick for title, but now when searching on the o…
Better solution to index a DataFrame according to the values of 2 others
I would like to index a DataFrame (aaxx_df) according to the values of 2 others (val1_df for the columns and val2_df for the rows). I put below a solution that works for my problem, but I guess, there must be some much cleaner solutions, possibly via SQL (it seems to me to be very similar to a relational data…
Execute a query for multiple sets of parameters with psycopg2
I have a table that I want to query, but I want to make many specific queries and return a table of any results that have met their condition, and ignore queries that do not exist. Hopefully this illustrates what I’m trying to achieve here… I want to perform a series of select statements which eac…
Pass Column Names into SQL statement in dynamic way – Python- SQL Server
Example of ‘fields’ value = name, surname, date I can put ‘fields’ in a list but I do not know how many (?) to put inside the query. Because, fields variable will include sometimes 5, sometimes 10 column names. I am trying to pass column names dynamically to the query. How can I solve …
Problems passing a Python String to SQL query
I got some issues passing my SQL query made in Python to MS SQL. Were talking about retrieving some code via pyodbc, editing it with regex, and passing it back into a new table of the Database. I also tried some print()-Commands to assure the Code is running in Python and being edited the right way, but I am …
Which cars have been rented together how many times? Which one is more easy to do MySQL or python?
I have a project about github but I represent like rent a car db for better understanding. I must find which cars have been rented together how many times from db. I have a 2 table: rent and car. I want to like this type of return I tried some queries to find this but I can’t. Also, I think
Can’t Insert into seperate column while using two select statements
TABLE: NAME : Jance C hiatt, Sam, Brook, Newyork, London ADDRESS : NULL,NULL,NULL,NULL NewYork and London should be address column but it is showing on Name itself Here address is not coming at the separate column of database. Kindly tell me what issue I am facing Answer Each insert statement creates new rows…
declare variable with pd.read_sql_query
Can someone explain why do I get an error when executing the following simple query with pandas: import pyodbc import pandas as pd connstr = ‘Driver={SQL Server}; Server=sr1; Database=db’ conn = …