I want a stored procedure in SQL Server to have two optional parameters, @CUSTOMERID and @ASSEMBLYID, and return a recordset. The procedure will only ever be called with just one of the two parameters specified. If the first one is specified I want the WHERE cause of the recordset to be "WHERE CustomerId = @CUSTOMERID", and if the second parameter is specified I want the WHERE clause to be "WHERE AssemblyId = @ASSEMBLYID". How can I dynamically create the where clause based on which parameter is provided? Can I save the SQL to a string variable and then somehow execute the string variable to generate and return the recordset?