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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Data Retrieval using Input parameters

Author  Topic 

lutha
Starting Member

2 Posts

Posted - 2005-02-22 : 05:42:51
can we retrieve data using input parameters in Mssql? If yes how can we do this?

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-02-22 : 05:52:26
you probably want a stored porcedure:

use northwind
go
create procedure spMyOrders
@CustomerId char(5) = null,
@employeeId int = null
as
select *
from orders
where (CustomerId = @CustomerId or @CustomerId is null) and
(employeeId = @employeeId or @employeeId is null)
go

exec spMyOrders null, null -- all data
exec spMyOrders 'VINET', null -- all data that have 'VINET' for customerId
exec spMyOrders null, 6 -- all data that have 6 for employeeId
exec spMyOrders 'VINET', 6 -- all data that have 'VINET' for customerId and 6 for employeeId

go

drop procedure spMyOrders


Go with the flow & have fun! Else fight the flow
Go to Top of Page
   

- Advertisement -