Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 passing optional parameters to stored proc

Author  Topic 

Swati Jain
Posting Yak Master

139 Posts

Posted - 2007-07-25 : 03:46:31
@ItemID ------>input parameter to stored procedure
If (@ItemID=Null) 'if null is passed as parameter value
....
...
execute if condition query
else
execute else condition query ('if null is not passed as the )parameter

what is the exact syntax for writing such type of stored procedures

I have written query as follows (How to write it exactly)
If Not ISNULL(@ItemID,N'')

SELECT DeliveryDetail.DeliveryNumber, DeliveryDetail.ItemID, DeliveryDetail.DeliverdQty, DeliveryDetail.OrderNumber,
DeliveryDetail.OrderLineNumber FROM DeliveryDetail INNER JOIN InvoiceHeader ON DeliveryDetail.DeliveryNumber = InvoiceHeader.DeliveryNumber
WHERE (InvoiceHeader.CompanyID = @CompanyID) AND (InvoiceHeader.DivisionID = @DivisionID) AND (InvoiceHeader.DepartmentID = @DepartmentID) AND
(InvoiceHeader.InvoiceNumber = @InvoiceNumber)AND (DeliveryDetail.ItemID=@ItemID)

else

SELECT DeliveryDetail.DeliveryNumber, DeliveryDetail.ItemID, DeliveryDetail.DeliverdQty, DeliveryDetail.OrderNumber,
DeliveryDetail.OrderLineNumber FROM DeliveryDetail INNER JOIN InvoiceHeader ON DeliveryDetail.DeliveryNumber = InvoiceHeader.DeliveryNumber
WHERE (InvoiceHeader.CompanyID = @CompanyID) AND (InvoiceHeader.DivisionID = @DivisionID) AND (InvoiceHeader.DepartmentID = @DepartmentID) AND
(InvoiceHeader.InvoiceNumber = @InvoiceNumber)

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-07-25 : 05:40:50
If @ItemID is not null


_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page
   

- Advertisement -