this stored procedure select data from database (whith search criteria and sort data by @order_by send by caller and default value is sr_id
when i execute this procedure this error will appear "Must declare the scalar variable "@p_result". " and i don't know why please if u can help me
Expand|Select|Wrap|Line Numbers
- ALTER PROCEDURE [dbo].[GridView_Sort] (
- @p_version nvarchar(100) = null, @p_result nvarchar(100) = null,
- @Salesman int = null , @from_Date datetime = null ,
- @to_date datetime = null,
- @order_by nvarchar(100) = null)
- AS
- BEGIN
- DECLARE @p_build nvarchar(max);
- if @order_by is null
- SET @order_by = ' order BY sr_id';
- SET @p_build = 'SELECT sr_id AS ID,
- sr_version AS Version,
- sm_name AS SalesMan_Names,
- CASE sr_result WHEN 1 THEN ''OK'' ELSE ''KO'' END AS Result,
- sr_comments AS Comments,
- sr_datetime AS Date
- FROM SYNC_RESULT ,SALESMAN
- WHERE sm_id = sr_sm_id and
- ((@p_version IS NOT NULL AND sr_version = @p_version) OR (@p_version IS NULL))
- and ((@p_result IS NOT NULL AND sr_result = @p_result) OR (@p_result IS NULL))
- and ((@Salesman IS NOT NULL AND sm_id = @Salesman) OR (@Salesman IS NULL))
- and ((@from_Date IS NOT NULL AND CONVERT(nvarchar(32),sr_datetime, 112) >= CONVERT(nvarchar(32),@from_Date, 112)) OR (@from_Date IS NULL))
- and ((@to_date IS NOT NULL AND CONVERT(nvarchar(32),sr_datetime, 112) <= CONVERT(nvarchar(32),@to_date, 112)) OR (@to_date IS NULL))' + @order_by
- EXEC sp_executesql @p_build ;
- END