我有一个存储过程。在这个存储过程中,我必须检查一个特定的参数是否为空。我怎样才能做到这一点?我写到:如何在sql server中检查参数是否为空?
ALTER PROCEDURE [dbo].[GetReelListings]
@locationUrlIdentifier VARCHAR(100)
AS
BEGIN
SET NOCOUNT ON;
declare @Sql varchar(max)=''
SET @Sql = 'SELECT CategoryName, CategoryUrlIdentifier, LocationUrlIdentifier, Directory.* FROM (SELECT ROW_NUMBER() OVER (PARTITION BY Category.Name ORDER BY CASE WHEN '''+ @locationUrlIdentifier + ''' = Location.UrlIdentifier THEN 1 ELSE CASE WHEN ''' + @locationUrlIdentifier + ''' IS NULL AND Directory.LocationId IS NULL THEN 0 ELSE 2 END END, Directory.SortOrder) AS ''RowNo'', Category.Name AS CategoryName, Category.UrlIdentifier AS CategoryUrlIdentifier, dbo.Location.UrlIdentifier AS LocationUrlIdentifier, Directory.DirectoryId, CASE WHEN ''' + @locationUrlIdentifier + ''' = Location.UrlIdentifier THEN 1 ELSE CASE WHEN ''' + @locationUrlIdentifier + ''' IS NULL AND Directory.LocationId IS NULL THEN 0 ELSE 2 END END AS CategoryOrder FROM dbo.Directory INNER JOIN dbo.Category ON Directory.CategoryId = Category.CategoryId LEFT OUTER JOIN dbo.Location ON dbo.Directory.LocationId = location.Location_ID) AS content INNER JOIN dbo.Directory ON content.DirectoryId = Directory.DirectoryId WHERE content.RowNo =1 '
if (@locationUrlIdentifier is null)
begin
SET @Sql = @Sql + ' and 1=1'
end
else
begin
SET @Sql = @Sql + ' and CategoryOrder = 1 '
end
print @SQl
EXECUTE (@Sql)
END
这将在SQL中工作,但这将在Codebehind中返回一个空数据集。
什么是错误 – codingbiz
这将在后面的数据集的代码没有什么回报,从而为null –
更好,如果你能前给完整的脚本。然后很容易找到问题 – Prasanna