Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Gsuttie
Starting Member
14 Posts |
Posted - 2001-02-27 : 04:04:59
|
| I have an asp page where you can filter say 8 fields. Depending on the input of the user in those 8 fields i need to create a stored proc using dynamic sql to create the query.If the user for instance misses out the first 6 text boxes then i just want to create a query on the last 2 fields. I need a stored proc not a sql string on the page.My Query is below -Where am i going wrong?declare @strSQL as varchar(255)declare @trade_cpty_sender_sub_id as intdeclare @trade_security_isin as varchar(50)declare @trade_settlement_date as datetimedeclare @trade_portfolio as varcharset @strSQL = "select top 100 * FROM t_live_trades l INNER JOIN t_user u ON l.trade_user_id = u.user_id INNER JOIN t_counterparty c ON l.trade_cpty_id = c.cpty_id and where "if 1 is not null begin strsql = strsql & " l.trade_cpty_id = @trade_cpty_id endend ifif @trade_cpty_sender_sub_id is not null begin strsql = strsql & " l.trade_cpty_sender_sub_id = @trade_cpty_sender_sub_id endend ifif @trade_timestamp is not null begin strsql = strsql & " AND l.trade_timestamp like @trade_timestamp endend if if @trade_security_isin is not null begin strsql = strsql & " AND l.trade_security_isin = @trade_security_isin endend ifif @trade_security_zip_code is not null begin strsql = strsql & " AND l.trade_security_zip_code = @trade_security_zip_code endend ifif @trade_settlement_date is not null begin strsql = strsql & " AND l.trade_settlement_date = @trade_settlement_date endend if if @trade_nominal is not null begin strsql = strsql & " AND l.trade_nominal = @trade_nominal endend if if @trade_portfolio is not null begin strsql = strsql & " AND l.trade_portfolio = @trade_portfolio endend if print (strSQL)exec (strSQL)Greg |
|
|
|
|
|