sql-server

SQL INSERT but increment ID if exist without having to do separate SELECT query

SQL INSERT but increment ID if exist without having to do separate SELECT query Question: I have a table with Primary Key on two columns: ID (Users ID) and SQ (Sequence, this starts at 1 and increments +1 for each ID). A user should not have multiple instances of the same sequence #. Here is …

Total answers: 2

How to connect to a MS SQL Server 2019 on another machine with Python?

How to connect to a MS SQL Server 2019 on another machine with Python? Question: The MS SQL server I am trying to connect with is in another machine within my corporate network. Many laboratory external devices write on the SQL service without issues, so I know that the server is configured to accept external …

Total answers: 1

UPDATE row with ID in Azure SQL table with pyodbc (passing variables)

UPDATE row with ID in Azure SQL table with pyodbc (passing variables) Question: I am attempting to update an entire row with a specific ID in my azure SQL database using pyodbc. I currently have the below query but know that the syntax is not correct. def update_invoice(fullName, invoiceNo, date, address, description, total, invoiceID): cursor.execute("UPDATE …

Total answers: 1

Pyodbc.connect is not connecting with created login and user

Pyodbc.connect is not connecting with created login and user Question: Been stuck on this for a few days. Seen quite a few stack overflow posts on this which hasn’t resolved for me and read the microsoft and pyodbc docs also but seems like my issue on this may be niche and would like some help. …

Total answers: 1

Python in Execute Process Task

Python in Execute Process Task Question: I have written a python code, then ran it through SSIS in the Execute Process Task, because I want to schedule it with table refresh dependency(which is not possible through windows scheduler or Alteryx). The code reads and writes to SQL management studio to translate via Google API (pip …

Total answers: 2

Can't get full data from SQL Server with python

Can't get full data from SQL Server with python Question: I’m trying to get query as a xml data from mssql server with pyodbc. After query, im writing data to new xml file with unique name. Everything works fine to this point with small data. Problem is when i try to read data over 2037 …

Total answers: 1

When pandas reads binary column incorrect values

Convert bytes in a pandas dataframe column into hexadecimals Question: There is a problem when pandas reads read_sql bytes column. If you look at the sql request through DBeaver, then the bytes column shows differently, but if you look at it through read_sql, it seems that pandas translates the value into a hex. For example, …

Total answers: 1

Python-Flask Sqlalchemy mssql – Total beginner

Not getting expected data from SQL Server in Python Question: I’ve been following a course, and I want to change my data source from sqlite to mssql. I’ve made the connection, and i’m trying to list the users in my db. But when I do I get the result show below: <Users 2> <Users 3> …

Total answers: 1

Reading SQL table from Python with merge condition

Reading SQL table from Python with merge condition Question: import pandas as pd conn = pyodbc.connect("Driver={??};" "Server=??;" "Database=??;" "Trusted_Connection=yes;") df1 = pd.read_sql_query("SELECT TOP 10000 * FROM table1", conn) df2 = pd.read_sql_query("SELECT * FROM table2 (((where id_key = id(from table1) ))) ", conn) Hello, I have two tables in SQL server. I wanted to pull the …

Total answers: 1

How to use a character '# in string?

How to use a character '# in string? Question: I am trying to conncect MSSQL DB to python, and the DB’s password has included a character ‘#’. Is there any way to use ‘#’ in string, not changing the password? Asked By: jhseo || Source Answers: You can use the character ‘#’ in a string …

Total answers: 2