Dies ist meine gespeicherte Prozedur, die Eingabe von Listbox und Anzeige von Datensätzen im Zusammenhang mit ausgewählten Element. aber wenn ich nichts aus Listbox auswähle, dann müssen alle Datensätze angezeigt werden, was nicht passiert ist.Wie übergeben Null-Wert an gespeicherte Prozedur in Sql
Das ist mein Stored Procedure
USE [MyDb]
GO
/****** Object: StoredProcedure [dbo].[usp_SearchCAMAFunctionalObsolescence] Script Date: 10/18/2016 12:30:08 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[usp_SearchCAMAFunctionalObsolescence]
@section as nvarchar(max),
@quality as nvarchar(max),
@style as nvarchar(max)
As
Begin
set nocount on;
Declare @Where as varchar(max)
Declare @Select as varchar(max)
Set @Select = ' Distinct vi.struct_no as structure,a.assesmt_no as assessment,a.parcel_no as parcel, o.own_last+'' , ''+o.own_first as taxpayer, id.year_built as built, id.effect_age as age, id.mkt_adj as fo, vi.aprais_val as mktvalue
From assessments a
inner join parcel p on a.parcel_no = p.parcel_no
inner join valueimp vi on vi.assesmt_no = a.assesmt_no
inner join owner o on o.id = a.owner_id
inner join imp_details id on id.improvementId = vi.id and (id.isdeleted is null or id.isdeleted = 0)
inner join quality_details qd on qd.quality_id = id.quality_id
inner join section_details sd on sd.section_id = id.section_id
inner join style_details stdl on stdl.style_id = id.style_id'
Set @Where = ' where (' + @section + ' is null or sd.section_id = ' + @section + ') and (' + @quality + ' is null or qd.quality_id = ' + @quality + ') and (' + @style + ' is null or stdl.style_id = ' + @style + ')'
DECLARE @QUERY NVARCHAR(MAX)
SET @QUERY= 'Select '+ @SELECT + @WHERE
print @QUERY
EXEC sp_executesql @QUERY , N'@section as int ,@quality as int,@style as int' ,@section ,@quality,@style
END
if i execute stored procedure in this way
// EXEC usp_SearchCAMAFunctionalObsolescence 'null','null','null'
it display all records.
but i need to execute stored procedure in this way
// EXEC usp_SearchCAMAFunctionalObsolescence null,null,null
and it not display anything
C# code? _______ – Imad
Verwenden Sie MySQL oder Oracle - oder vielleicht andere dbms? Markieren Sie keine nicht betroffenen Produkte. – jarlh