Skip to content
Advertisement

Scan a single column in SQL Server for a data entry using python

Example of a column:

Single column table

This is what I have tried. I only want to search based on a single column in the table. Lets says the table name is Employees. The input parameter is entered by the user in console.

exists = cursor.execute("SELECT TOP 1 * FROM Employees WHERE ID = ?", (str(input),))
print(exists)
if exists is None:
    return False
else:
    return True

Advertisement

Answer

I think this is what you are looking for:

insert_query = '''SELECT TOP 1 * FROM EmployeeTable WHERE ID = (?);''' # '?' is a placeholder
cursor.execute(insert_query, str(input))
  
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement