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 2005 Forums
 Transact-SQL (2005)
 case query

Author  Topic 

abcd
Yak Posting Veteran

92 Posts

Posted - 2009-02-19 : 04:45:10
hi all...
I have two tables File and book
Format for the tables is as follows..
FOR FILE TABLE
FileId
,CompanyId
,DeptId
,GroupId
,VoucherId
,YearId
,LocationId
,FileNo
,CreatedOn
,CreatedBy
,BookNo
,Description

FOR BOOK TABLE
LabelId
,CompanyId
,DeptId
,GroupId
,LocationId
,VoucherId
,YearId
,FromDate
,ToDate
,VoucherSNo1
,VoucherSNo2
,BookNo
,CreatedOn
,CreatedBy
,Description

I want to make a procedure in which there are two parameters @locationid,@type
If type is 'f' then i want to select full detail from file table else select detail from book table...

Do suggest some way out...

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-02-19 : 04:50:52
[code]
create proc usp_samp
(@locationid int,
@type varchar(4)
)
set nocount on

if (@type ='f')

select * from filetable where locationid = @locationid
else
select * from booktable where locationid = @locationid

set nocount off
[/code]
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-02-19 : 05:00:18
quote:
Originally posted by bklr


create proc usp_samp
(@locationid int,
@type varchar(4)
)
set nocount on

if (@type ='f')

select * from filetable where locationid = @locationid
else
select * from booktable where locationid = @locationid

set nocount off




Some corrections there,

CREATE proc usp_samp 
(@locationid int,
@type varchar(4)
) as
begin
set nocount on

if (@type ='f')

select * from filetable where locationid = @locationid
else
select * from booktable where locationid = @locationid


set nocount off
end
Go to Top of Page

abcd
Yak Posting Veteran

92 Posts

Posted - 2009-02-19 : 05:11:42
hey saket a lot!!!!!
:):)
Ur query solved my problem....
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-02-19 : 05:27:03
np
Go to Top of Page
   

- Advertisement -