I have a streamlit app that retrieve data from sql server database where i am using pyodbc.
I have an select query where i try to select data based on user input using wild card inside the sql query.
The problem is that when the user search on any field beside the ID it does not return anything.
database:
CREATE TABLE [dbo].[t1](
[ID] [int] IDENTITY(1,1) NOT NULL,
[first] [nvarchar](50) NULL,
[last] [nchar](50) NULL,
[Rating] [int] NULL,
CONSTRAINT [PK_t1] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
python code:
import pandas as pd
import streamlit as st
advanced_search_term_list = []
if len(advanced_search_term_list)>0:
sql="select * from testDB.dbo.t1 where (ID = ? OR ID is null) and (first LIKE ? OR first is null) and (last LIKE ? or last is null) and (Rating = ? or Rating is null) "
param0=advanced_search_term_list[0]
param1=f'%{advanced_search_term_list[1]}%'
param2=f'%{advanced_search_term_list[2]}%'
param3=advanced_search_term_list[3]
rows = cursor.execute(sql,param0,param1,param2,param3).fetchall()
the query just return data of the param0
where is the error in my code ??