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)
 How to pass parameter to procedure..

Author  Topic 

companionz
Yak Posting Veteran

54 Posts

Posted - 2009-07-17 : 00:55:29
I've to write a procedure in which i need to pass a parameter like..

Create Procedure Test_Proc
@FromDt DateTime,
@ToDt DateTime,
@CompanyUid Int
Begin

select name from company where uid in @Companyuid

--- i mean, i can have multiple companies for this parameter..
What should be the datatype then.. and if possible give me an example of how to execute also..

How to go about this?

Thanks,
Sourav

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-07-17 : 00:58:19
see
http://www.sommarskog.se/arrays-in-sql-2005.html
http://vyaskn.tripod.com/passing_arrays_to_stored_procedures.htm



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-07-17 : 05:03:57
try any one of these

declare @Companyuid varchar(max),@str varchar(max)
select @Companyuid ='1,2,5',@str =''

select name from company where '%,' + @Companyuid+ ',%' LIKE '%,' + CAST( id AS VARCHAR(255)) +',%'

select @str = 'select name from company where cast(id as varchar) in('+@Companyuid+')')

exec (@str)
select name from company where patindex('%,' + CAST( id AS VARCHAR(255)) +',%',','+@Companyuid+',' )>0
Go to Top of Page
   

- Advertisement -