eveCalypso
Programmer
Dear All,
I am delving into dynamic stored procedures. I think what I want to do is pretty straight forward. I have 5 possible paramters of which only 2 will always be present (dates).
So, for example:
@anIDColumn int
@toDate datetime
@fromDate datetime
@anInvoiceID int
@BinID char(12)
I want a dynamic stored procedure which will decide which parameters are needed based on what comes into the procedure.
I learnt about EXEC @sqlStr
which is a String I can build, but because I need to convert all the fields to varChar(x), my dates are in the wrong format and the query fails!!
So I then tried sp_executeSql, but I can only set up the SQL statement once - which means that, for example, excluding the invoice number OR setting the invoice to null or setting it to a specific value requires different SQL wording every time - based on the incoming value...
Does anyone have any idea what I could do to make this selection work?? What I am doing is asking the user for search inputs to narrow down which transactions they want to see for an Edit. (between dates, specific invoice, specific item etc).
Any advice would be appreciated.
Regards,
EvE
I am delving into dynamic stored procedures. I think what I want to do is pretty straight forward. I have 5 possible paramters of which only 2 will always be present (dates).
So, for example:
@anIDColumn int
@toDate datetime
@fromDate datetime
@anInvoiceID int
@BinID char(12)
I want a dynamic stored procedure which will decide which parameters are needed based on what comes into the procedure.
I learnt about EXEC @sqlStr
which is a String I can build, but because I need to convert all the fields to varChar(x), my dates are in the wrong format and the query fails!!
So I then tried sp_executeSql, but I can only set up the SQL statement once - which means that, for example, excluding the invoice number OR setting the invoice to null or setting it to a specific value requires different SQL wording every time - based on the incoming value...
Does anyone have any idea what I could do to make this selection work?? What I am doing is asking the user for search inputs to narrow down which transactions they want to see for an Edit. (between dates, specific invoice, specific item etc).
Any advice would be appreciated.
Regards,
EvE