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
 General SQL Server Forums
 New to SQL Server Programming
 SQL Statement

Author  Topic 

avmreddy17
Posting Yak Master

180 Posts

Posted - 2006-08-29 : 11:33:16
SenderCompID
OnBehalfOfCompID
SenderSubID
AccountID
FirmCodeExternal
AccountIndex

I have the above five Columns in table and I need a SP
which will take

SenderCompID
OnBehalfOfCompID
SenderSubID
AccountID

as I/P parameters and in the table the I/p Parameters might have values in the four Colums or just one Column or two or three

and Return

FirmCodeExternal
AccountIndex

Data

SenderCompID OnBehalfOfCompID SenderSubID AccountID FirmCodeExternal AccountIndex
T1 NULL T2 NULL XXX
1

If any one of the I/P parameters matches I need to return FirmCodeexternal and AccountIndex

Thanks for any help on this

Thx
Venu

nr
SQLTeam MVY

12543 Posts

Posted - 2006-08-29 : 11:39:52
create proc x
@SenderCompID int ,
@OnBehalfOfCompID int ,
....
as
select FirmCodeExternal, AccountIndex
from tbl
where (SenderCompID = @SenderCompID or @SenderCompID is null)
and (OnBehalfOfCompID = @OnBehalfOfCompID or @OnBehalfOfCompID is null)
.....
go


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-08-29 : 11:49:14
or

where
Isnull(@SenderCompID,SenderCompID)=SenderCompID
and
Isnull(@OnBehalfOfCompID ,OnBehalfOfCompID )=OnBehalfOfCompID


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -