我有一個存儲過程。在這個存儲過程中,我必須檢查一個特定的參數是否爲空。我怎樣才能做到這一點?我寫到:如何在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